Author Topic: BlitzBasic like Syntax  (Read 3473 times)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5024
  • O Rly?
    • View Profile
BlitzBasic like Syntax
« on: 2008-Jan-06 »
Hab mal angefangen ein ImageHandling und kleinigkeiten wie bei BlitzBasic zu machen.

Bilder z.B werden per Variable "gehandelt", siehe Codebeispiel

wers braucht!

Codebeispiel:

Code: GLBasic [Select]
// - Load Images ----------------------------------
GLOBAL Img1 = LoadImage("pic.png")
GLOBAL Img2 = LoadImage("pic.png")
GLOBAL Img3 = LoadImage("pic.png")
// ------------------------------------------------


MidHandleImage(Img1) //\
MidHandleImage(Img2) //--> Setze Ausgangspunk des Images in die Bildmitte

WHILE TRUE
KeyHitUpdate()

        DrawImage(Img1,320,240)
        DrawImage(Img2,MouseX(),MouseY())
        DrawImage(Img3,100,100)
       
        IF KeyDown(57) THEN PRINT "PRESSED",10,10       // Space
        IF KeyHit(47) THEN PRINT "KeyHit",10,30         // V
       
        IF MouseHit(1) AND ImagesCollide(Img2, Img1) // linke Maustaste und Collision
                PRINT "COLLISION",500,10
        ENDIF
       
        IF MouseHit(1) AND ImagesCollide(Img2, Img3) // linke Maustaste und Collision
                PRINT "COLLISION",500,10
        ENDIF

SHOWSCREEN
WEND
END
Hier die BB.gbas:

Code: GLBasic [Select]
// --------------------------------- //
// Project: BB-Syntax
// Version: 0.1 Alpha
// IDE Version: 5.119
// --------------------------------- //



TYPE Image
        ID              // Spritenumber
        X;Y             // Position
        XX;YY   // width and height
        Midhand // 0 = off , 1 = on
ENDTYPE

GLOBAL TImage[] AS Image

// --------------------------------------------------------
// - Functions --------------------------------------------
// --------------------------------------------------------

FUNCTION _GetImageID:
LOCAL XX, YY, num
    GETSPRITESIZE num, XX, YY
    WHILE XX>0
        INC num, 1
        GETSPRITESIZE num, XX, YY
    WEND
    RETURN num
ENDFUNCTION


// --------------------------------------------------------
// - Images -----------------------------------------------
// --------------------------------------------------------
//      TYPE Image
//              ID              // Spritenumber
//              X;Y             // Position
//              XX;YY   // width and height
//              Midhand // 0 = off , 1 = on
//      ENDTYPE
// --------------------------------------------------------
FUNCTION LoadImage: file$
LOCAL t AS Image
LOCAL num
        t.ID = _GetImageID()
        LOADSPRITE file$,t.ID
        GETSPRITESIZE t.ID,t.XX,t.YY
        DIMPUSH TImage[],t
        RETURN t.ID
ENDFUNCTION

FUNCTION DrawImage: handle, x, y        // handle = Name from LoadImage, example: IMG = LoadImage("img.png") use IMG !
        TImage[handle].X = x
        TImage[handle].Y = y
        IF TImage[handle].Midhand = FALSE
                DRAWSPRITE TImage[handle].ID, TImage[handle].X, TImage[handle].Y
        ELSE
                DRAWSPRITE TImage[handle].ID, TImage[handle].X-TImage[handle].XX/2, TImage[handle].Y-TImage[handle].YY/2
        ENDIF
ENDFUNCTION

FUNCTION MidHandleImage: handle
        TImage[handle].Midhand = TRUE
ENDFUNCTION

FUNCTION ImagesCollide: handle, handle2  // handle = image variable, handle2 = image variable 2
LOCAL x1, y1, x2, y2, col

        IF TImage[handle].Midhand = FALSE
                x1 = TImage[handle].X
                y1 = TImage[handle].Y
        ELSE
                x1 = TImage[handle].X - TImage[handle].XX/2
                y1 = TImage[handle].Y - TImage[handle].YY/2
        ENDIF

        IF TImage[handle2].Midhand = FALSE
                x2 = TImage[handle2].X
                y2 = TImage[handle2].Y
        ELSE
                x2 = TImage[handle2].X - TImage[handle2].XX/2
                y2 = TImage[handle2].Y - TImage[handle2].YY/2
        ENDIF

        col =  SPRCOLL(TImage[handle].ID, x1, y1, TImage[handle2].ID, x2, y2)

        RETURN col
ENDFUNCTION


// --------------------------------------------------------
// - Input -----------------------------------------------
// --------------------------------------------------------
//
// --------------------------------------------------------

FUNCTION MouseX:
LOCAL mx,my,b1,b2
MOUSESTATE mx, my, b1, b2

        RETURN mx
ENDFUNCTION

FUNCTION MouseY:
LOCAL mx,my,b1,b2
MOUSESTATE mx, my, b1, b2

        RETURN my
ENDFUNCTION

FUNCTION MouseHit: num// 1 = left, 2 = right, 3 = mouseweel
LOCAL but
        IF num = 1 THEN but = 3
        IF num = 2 THEN but = 4
        IF num = 3 THEN but = 5

        IF MOUSEAXIS(but) THEN RETURN TRUE
ENDFUNCTION


// Update keyboard state
FUNCTION KeyHitUpdate:
GLOBAL gKeyDown[], gKeyState[]
LOCAL  k, i
    // First Time call/ zum ersten Mal hier
    IF BOUNDS(gKeyDown[],0)=0
        DIM gKeyDown[256]
        DIM gKeyState[256]
    ENDIF

    // For each key / für jede Taste
    FOR i=0 TO 255
        k = KEY(i)
        // Key is pressed / Taste ist gedrückt
        IF k
            IF gKeyDown[i]
                gKeyState[i]=1
            ELSE
                gKeyDown[i]=1
                gKeyState[i]=2
            ENDIF
        ELSE
            // Key is not pressed / Taste nicht gedrückt

            // Has key been pressed before?
            // War die Taste gedrückt?
            IF gKeyDown[i]
                gKeyDown[i] = 0
                gKeyState[i] = -1
            ELSE
                gKeyState[i]=0
            ENDIF
        ENDIF
    NEXT
ENDFUNCTION


FUNCTION GetKeyStat: nkey//  0 = not pressed; 1 = pressed; 2 = just pressed; -1 = release event
    RETURN gKeyState[nkey]
ENDFUNCTION

FUNCTION KeyHit: nkey
        IF GetKeyStat(nkey) = 2 THEN RETURN TRUE
ENDFUNCTION

FUNCTION KeyDown: nkey
        IF GetKeyStat(nkey) = 1 THEN RETURN TRUE
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
BlitzBasic like Syntax
« Reply #1 on: 2008-Jan-07 »
Neu, Neu, Neu: LOADANIM/DRAWANIM (mach das net doppelt ;) )

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5024
  • O Rly?
    • View Profile
BlitzBasic like Syntax
« Reply #2 on: 2008-Jan-07 »
Sehr geil Gernot, nur eins gefällt mir nicht !
Das man angeben muss, x und y bei DRAWANIM...quasi immer eine doppelte For-Schleife braucht!
Könnte man das nicht auch intern Regeln?
Oder brauchst du das, da du ja ein ANIM-Image immer auf eine ID von Sprites legst?
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
BlitzBasic like Syntax
« Reply #3 on: 2008-Jan-07 »
Äh... Willst Du die Kacheln immer auf 0,0 zeichnen?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5024
  • O Rly?
    • View Profile
BlitzBasic like Syntax
« Reply #4 on: 2008-Jan-07 »
Ok ich seh schon irgendwas versteh ich da wohl nicht ganz!

LOADANIM datei$, id%, w%, h%

Die id% ist die StartID(SpriteSlot) der Zählung, oder die SpriteID die immer um 1 erhöht wird(Sprich id% = frame0, id%+1 wär dann frame1 usw)?

EDIT:

OK du benutzt nur eine SpriteID, Sehr gut :D !
Wie wärs wenn LOADANIM die Anzahl der Tiles zurückliefert?
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
BlitzBasic like Syntax
« Reply #5 on: 2008-Jan-07 »
Also - loadanim läd nur "1" Sprite. Das muss man dann mit DRAWANIM zeichnen.
Ich bau später noch eine Funktion, die ein Sprite zerschnipseln kann und 1000 Sprites erzeugt.