BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Steinbock

Pages: 1 2 [3] 4
31
GLBasic - de / Spritebuffer direkt beschreiben
« on: 2009-Nov-05 »
Hallo zusammen

Gibt es in GLBasic die Möglichkeit direkt in den Bitmapbuffer eines Sprites zu schreiben auser mit SETPIXEL?

32
Bug Reports / Re: help! ATTENTION!NOTICE!!!
« on: 2009-Oct-04 »
double dot? ;/

33
That's the whole truth.  :good:

34
If you mean an attached "ZIP-code", then there is none.
In the first part it's a small "motivation" to do a little own work.  =D

35
Ok. Should be fixed.  :whistle:

36
Simple tilemap editor is now available.
See "EDIT" in first post topic http://www.glbasic.com/forum/index.php?topic=2950.0

37
Of course!   =D
Original sourcecode is written in Delphi. Please give me a week or two, so i can
rewrite it in GLBASIC. I think this makes more sense.

38
GLBasic - en / Re: Wiz games - music stutters?
« on: 2009-Jun-01 »
OGG-File is zipped in attachement (maybe other need it too).

I'm using
Code: GLBasic [Select]
        PLAYMUSIC "./isdo/sfx/music.ogg",TRUE
        MUSICVOLUME 0.8
 


[attachment deleted by admin]

39
GLBasic - en / Re: Wiz games - music stutters?
« on: 2009-Jun-01 »
Quote
Steinbock: Are you saying that the game stutters for you too?
Yes.

With my own program MP3 stutters but OGG works fine.

40
GLBasic - en / Re: Wiz games - music stutters?
« on: 2009-Jun-01 »
By me it works with OGG (MP3 stutters too). WIZ-FW 1.0.0 and newest downloadable glbasic demo-version 6.247.

41
GLBasic - en / Re: Wiz games - music stutters?
« on: 2009-Jun-01 »
Try to play the music as OGG instead of MP3.

42
In the last part we look, how to add a power-up and thus change the shotpower.
Then finally we add a backgroundmusic and some soundeffects. As always there is an attachement with samplecode.

If you worked through the 6th part, you know, we have 2 different enemytypes: ENEMY1 and ENEMY2.
In the program we can see ENEMY2 as RED enemy. Now this one shall, if it is hitted, leave a power-up.
For this we just have to add an object in our EnemySCRIPT.
Code: GLBasic [Select]
                ObjectADD(ID_POWERUP,Object.PosX[ix],Object.PosY[ix])
 
The script for the power-up item on the other hand you will find in file items.gbas.
Code: GLBasic [Select]
        CASE ID_POWERUP
            SELECT Object.State[ix]
                CASE 1
                    IF Object.PosX[ix]>-16
                        DEC Object.PosX[ix],0.5
                    ELSE
                        Object.State[ix]=0
                    ENDIF
            ENDSELECT
            DRAWSPRITE SPR_POWERUP,Object.PosX[ix],Object.PosY[ix]
            SetCollBox(ix,0,0,15,15)
            IF CheckCollPlayer(ix)=COLL_PLAYER
                Object.State[ix]=0
                PLAYSOUND(SFX_EXTRA,GetPan(Object.PosX[ix]),0.7)
                SPR_SHOT=24
            ENDIF
    ENDSELECT
 
We check this item on collision with the player. If a collision occurs, we close the item in the objectlist and change our shot.

Now to the sound. This is an easy thing under GLBasic.
In file level000.gbas we load our soundeffects and allocate them a constant.
Code: GLBasic [Select]
    LOADSOUND "./isdo/sfx/shot.wav",SFX_SHOT,4
    LOADSOUND "./isdo/sfx/explosion.wav",SFX_EXPLOSION,4
    LOADSOUND "./isdo/sfx/extra.wav",SFX_EXTRA,4
 
Thereafter we load our backgroundmusic, setting the volume and play it.
Code: GLBasic [Select]
    PLAYMUSIC "./isdo/sfx/music.wav",TRUE
    MUSICVOLUME 0.9
 

In GLBasic a soundeffect will be played with the command PLAYSOUND.
If you look on the ItemSCRIPT for example
Code: GLBasic [Select]
 
                PLAYSOUND(SFX_EXTRA,GetPan(Object.PosX[ix]),0.7)
 
the soundeffect with ID SFX_EXTRA will be played with a volume of 0.7.
Function GetPan in our library causes, the effect sounds depending of objectposition (left/right).

Ok. That's it. Now i hope to helped some of you with this tutorial. And as i said, if i can help someone, i will try to do.

As a little bonus you can download here isdo_090406.zip - 11.13MB a 1min section of my project I.S.D.O. The playercollision is off. The backgroundmusics origin: "MOD-Archiv".
Code: GLBasic [Select]
Steuerung->WIN:
  startmenu:  cursorkey up/down = menucursor up and down
              "x"-key           = select menuentry
  game:       cursorkey up/down = move
              "x"-key           = shoot
              ENTER-key         = return to startmenu
 
And now enjoy!!  =D


   

[attachment deleted by admin]

43
Im letzten Teil schauen wir, wie ein Power-Up hinzugef?gt werden kann und wie dadurch die Schusskraft ver?ndert wird.
Und zum Abschluss f?gen wir noch eine Hintergrundmusik sowie einige Soundeffekte dazu. Wie immer findet ihr im Anhang den Beispiel-Code.

Wenn ihr den letzten Teil durchgearbeitet habt, wisst ihr ja, dass wir 2 verschiedene Gegnertypen haben: ENEMY1 und ENEMY2.
Im Programm selber kann man ENEMY2 als ROTEN Gegner erkennen. Nun soll dieser, falls er getroffen wird, ein Power-Up hinterlassen.
Dazu m?ssen wir nur in unserm EnemySCRIPT ein neues Objekt hinzuf?gen.
Code: GLBasic [Select]
                ObjectADD(ID_POWERUP,Object.PosX[ix],Object.PosY[ix])
 
Das Script f?r das Power-Up findet ihr wiederum in der Datei items.gbas.
Code: GLBasic [Select]
        CASE ID_POWERUP
            SELECT Object.State[ix]
                CASE 1
                    IF Object.PosX[ix]>-16
                        DEC Object.PosX[ix],0.5
                    ELSE
                        Object.State[ix]=0
                    ENDIF
            ENDSELECT
            DRAWSPRITE SPR_POWERUP,Object.PosX[ix],Object.PosY[ix]
            SetCollBox(ix,0,0,15,15)
            IF CheckCollPlayer(ix)=COLL_PLAYER
                Object.State[ix]=0
                PLAYSOUND(SFX_EXTRA,GetPan(Object.PosX[ix]),0.7)
                SPR_SHOT=24
            ENDIF
    ENDSELECT
 
Dieses Item ?berpr?fen wir nun auf die Kollision mit dem Spieler und falls eine stattfindet l?schen wir das Item in der Objektliste und ver?ndern unseren Schuss.

Nun Zum Thema Sound. Das is unter GLBasic eine einfache Sache.
In der Datei level000.gbas laden wir unsere Soundeffekte und weisen ihnen gleich eine Konstante zu.
Code: GLBasic [Select]
    LOADSOUND "./isdo/sfx/shot.wav",SFX_SHOT,4
    LOADSOUND "./isdo/sfx/explosion.wav",SFX_EXPLOSION,4
    LOADSOUND "./isdo/sfx/extra.wav",SFX_EXTRA,4
 
Dann laden wir unsere Hintergrundmusik, stellen die Lautst?rke ein und lassen sie laufen.
Code: GLBasic [Select]
    PLAYMUSIC "./isdo/sfx/music.wav",TRUE
    MUSICVOLUME 0.9
 

Eine Soundeffekt wird in GLBasic mit dem Befehl PLAYSOUND abgespielt.
Wenn Ihr zum Beispiel das ItemSCRIPT beachtet wird mit
Code: GLBasic [Select]
 
                PLAYSOUND(SFX_EXTRA,GetPan(Object.PosX[ix]),0.7)
 
Der Sound mit der ID SFX_EXTRA mit der Lautst?rke 0.7 abgespielt.
Die Funktion GetPan in unserer Library bewirkt, dass der Soundeffekt je nach Position des Objekts eher Links oder Rechts ert?nt.

So. Nun hoffe ich, dass ich dem einen oder anderen mit diesem Tutorial etwas geholfen habe. Und wie gesagt wenn ich irgendwo helfen kann, versuch ich's.

Als kleinen Bonus k?nnt Ihr hier isdo_090406.zip - 11.13MB einen ca. 1-min?tigen Ausschnitt aus meinem Projekt I.S.D.O herunterladen.
Die Spielerkollision ist noch ausgeschaltet. Die Hintergrundmusik stamm aus dem "MOD-Archiv".
Code: GLBasic [Select]
Steuerung->WIN:
  startmenu:  cursorkey up/down = menucursor up and down
              "x"-key           = select menuentry
  game:       cursorkey up/down = move
              "x"-key           = shoot
              ENTER-key         = return to startmenu
 
Viel Spass!!  =D


   

[attachment deleted by admin]

44

In the second last part of this tutorial we will first automate the adding of objects. Thereafter we will concerne with collisions.

Last time we added with
Code: GLBasic [Select]
        IF ScrollX=128 THEN ObjectADD(ID_ENEMY1,320,120)
        IF ScrollX=160 THEN ObjectADD(ID_ENEMY2,320,120)
 
in level00.gbas the objects manually. But in a completed game are much more required, and it would be very laborious to call every single object separatly. Therefore we read out the datas from a predefined file level00.evt. For this we must expand our existing event-type (TEvent).
Code: GLBasic [Select]
        IX%             =   0
        ID%[256]
        Pos%[256]
        X%[256]
        Y%[256]
 
IX is a pointer to the actual listentry, ID is the objectID, Pos is the scrollposition WHEN the object shall appear and X,Y the position WERE the object shall appear.
With
Code: GLBasic [Select]
    // init events
    OPENFILE(1,"./isdo/level00.evt",TRUE)
    FOR p=0 TO 254
        READUWORD 1,val
        Event.Pos[p]=val
    NEXT
    FOR p=0 TO 254
        READUWORD 1,val
        Event.ID[p]=val
    NEXT
    FOR p=0 TO 254
        READUWORD 1,val
        Event.X[p]=val
    NEXT
    FOR p=0 TO 254
        READUWORD 1,val
        Event.Y[p]=val
    NEXT
 
in level00.gbas we load these datas into our eventlist. The request when a object shall appear, we do in the subroutine EventHANDLER in library.gbas.
Code: GLBasic [Select]
//=============================================================================
  SUB EventHANDLER:
//=============================================================================

LOCAL   ix%,typ%

    ix=Event.IX
    IF ScrollX=Event.Pos[ix]
        SELECT Event.ID[ix]
            CASE ID_ENEMY1 TO ID_ENEMY2
                ObjectADD(Event.ID[ix],Event.X[ix],Event.Y[ix])
        ENDSELECT
        INC Event.IX,1
    ENDIF

ENDSUB // EventHANDLER
 
First we request the current index in the eventlist, then we check the type and add the corresponding object to the scene. The rest goes as if by magic.

And now to the collisions. There are different possibilities in GLBasic.
    BOXCOLL cheks, if 2 rectangles interleaf eachother
    SPRCOLL check, if visible pixels of 2 sprites interleaf eachother
We use a routine based on BOXCOLL. For this we define a so-called collisionbox for player, playershots and objects. This box can also be bigger or smaller then the sprite.
We have to expand the types.
Code: GLBasic [Select]
        CollTop
        CollBottom
        CollLeft
        CollRight
 
The size of the collisionbox of objects we specify with function
Code: GLBasic [Select]
//=============================================================================
  FUNCTION SetCollBox: ix%,left,top,right,bottom
//=============================================================================

    Object.CollLeft[ix]=Object.PosX[ix]+left
    Object.CollTop[ix]=Object.PosY[ix]+top
    Object.CollRight[ix]=Object.PosX[ix]+right
    Object.CollBottom[ix]=Object.PosY[ix]+bottom
 
For test pruposes you can outcomment the following 3 lines. Then the collisionboxes appear half-transparent.
Code: GLBasic [Select]
    //ALPHAMODE 0.5
    //DRAWRECT Object.CollLeft[ix],Object.CollTop[ix],Object.PosX[ix]+right-Object.CollLeft[ix],Object.PosY[ix]+bottom-Object.CollTop[ix],0xFFFFFF
    //ALPHAMODE 0.0
 

For the player we build a separate box.
Code: GLBasic [Select]
//=============================================================================
  SUB PlayerHANDLER:
//=============================================================================

    Player.CollTop=Player.PosY
    Player.CollBottom=Player.PosY+31
    Player.CollLeft=Player.PosX
    Player.CollRight=Player.PosX+16
    DRAWSPRITE SPR_PLAYER+(INTEGER((BAND(Player.Timer,3)/2))),Player.PosX,Player.PosY

ENDSUB // PlayerHANDLER
 
the same for the 8 shots in ShotHANDLER.
Code: GLBasic [Select]
                    Shot.CollTop   [ix]=Shot.PosY[ix]
                    Shot.CollBottom[ix]=Shot.PosY[ix]+6
                    Shot.CollLeft  [ix]=Shot.PosX[ix]
                    Shot.CollRight [ix]=Shot.PosX[ix]+6
 
It's important to make the assignements with every change of position.

Now the check if an object collides eather with player or with playershot.
Code: GLBasic [Select]
//=============================================================================
  FUNCTION CheckCollPlayer: ix%
//=============================================================================

    IF Player.CollTop>Object.CollBottom[ix] OR Player.CollBottom<Object.CollTop[ix] OR Player.CollLeft>Object.CollRight[ix] OR Player.CollRight<Object.CollLeft[ix]
        RETURN COLL_NONE
    ELSE
        RETURN COLL_PLAYER
    ENDIF

    RETURN COLL_NONE
 
With ix we pass the index of object wich we check. If the object touches the player we return COLL_PLAYER, else we return COLL_NONE.
The same for playershots.
Code: GLBasic [Select]
//=============================================================================
  FUNCTION CheckCollShot: ix%
//=============================================================================

LOCAL   i%

    FOR i=0 TO Shot.Count-1
        IF Shot.State[i]
            IF Shot.CollTop[i]>Object.CollBottom[ix] OR Shot.CollBottom[i]<Object.CollTop[ix] OR Shot.CollLeft[i]>Object.CollRight[ix] OR Shot.CollRight[i]<Object.CollLeft[ix]
                RETURN COLL_NONE
            ELSE
                Shot.State[i]=0
                RETURN COLL_SHOT
            ENDIF
        ENDIF
    NEXT

    RETURN COLL_NONE

ENDFUNCTION // CheckCollShot
 
But this time we return COLL_SHOT and clear also the current shotentry.

We give the command for collisiondetection for every object in the scripts. As example we take ID_ENEMY1 in enemies.gbas:
Code: GLBasic [Select]
            SetCollBox(ix,0,0,15,15)
 
Sets the size of collisionbox.
Then we check if ENEMY1 was hitted by a playershot.
Code: GLBasic [Select]
            IF CheckCollShot(ix)=COLL_SHOT
                Object.State[ix]=0
                EffectADD(ID_EFFECT1,Object.PosX[ix],Object.PosY[ix])
            ENDIF
 
If yes, we clear the object out of the list and add an effect (explosion).
Effect are nothing else than object but they do not need a collisionbox. The reason to distinguish between effects and objects is
Code: GLBasic [Select]
        GOSUB KeyHANDLER
        GOSUB LayerBGDRAW
        GOSUB ShotHANDLER
        GOSUB EventHANDLER
        GOSUB ObjectHANDLER
        GOSUB PlayerHANDLER
        GOSUB LayerFGDRAW
        GOSUB EffectHANDLER
        GOSUB StatusDRAW
 
that we draw effects AFTER objects. Otherwise perhaps we can' see the effects behind other objects.









[attachment deleted by admin]

45
Hallo BumbleBee

Quote
Aber bevorzuge doch lieber den einfacheren Weg
Was meint du damit? :|

Pages: 1 2 [3] 4