Menu

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.

Show posts Menu

Messages - hanyon21

#1
Thank you very much.
I changed alien image files.
Original frame has one frame per one image.
So I increased ten frames per each emage and did set LIMITFPS to 25.

For example, changed alien1 frame is below.
#2
I make space invader game.
Code (glbasic) Select

SETSCREEN 448,512,0
LIMITFPS 2

SETTRANSPARENCY RGB(0,0,0)

LOADANIM "ship.bmp",0,32,16

LOADSPRITE "bullet.bmp",1

LOADANIM "alien1.bmp",2,32,16
LOADANIM "alien2.bmp",3,32,16
LOADANIM "alien3.bmp",4,32,16

GLOBAL px=224
GLOBAL py=432
GLOBAL speed=2
GLOBAL pldir=2
GLOBAL planim=0

GLOBAL bulletspeed=20
GLOBAL bulletfired=0

TYPE bullet
bulx
buly
buldifx
buldify
ENDTYPE
GLOBAL bullets[] AS bullet

TYPE enemy
enx
eny
difx
dify
    frame
status

ENDTYPE
GLOBAL enemy1[] AS enemy
GLOBAL enemy2[] AS enemy
GLOBAL enemy3[] AS enemy

GLOBAL en1 AS enemy
GLOBAL en2 AS enemy
GLOBAL en3 AS enemy



Init_Game_Objects()

WHILE KEY(01)=FALSE

UpdateBullets()
UpdatePlayer()
    UpdateEnemy()
DrawTheScreen()

WEND

END



FUNCTION AddBullet:

LOCAL bull AS bullet

bull.bulx=px
bull.buly=py-10

bull.buldifx=0
bull.buldify=-8

DIMPUSH bullets[],bull
        bulletfired=bulletspeed


ENDFUNCTION

FUNCTION UpdateBullets:

FOREACH bull IN bullets[]
bull.bulx=bull.bulx+bull.buldifx
bull.buly=bull.buly+bull.buldify
IF bull.bulx<0 OR bull.bulx>448 OR bull.buly<0 OR bull.buly>512 THEN DELETE bull
NEXT

ENDFUNCTION

FUNCTION UpdatePlayer:

LOCAL dirx,diry

IF KEY(203) THEN dirx=-1
IF KEY(205) THEN dirx=1

px=px+(speed*dirx)

IF px<0 THEN px=0
IF px>448 THEN px=448

IF dirx=-1 THEN pldir=0
IF dirx=1 THEN pldir=1

IF bulletfired=0
IF KEY(29) OR KEY(157) THEN AddBullet()
ELSE
bulletfired=bulletfired-1
ENDIF

ENDFUNCTION

FUNCTION UpdateEnemy:

FOREACH en1 IN enemy1[]
en1.frame=en1.frame+1
NEXT

FOREACH en2 IN enemy2[]
en2.frame=en2.frame+1
NEXT

FOREACH en3 IN enemy3[]
en3.frame=en3.frame+1
NEXT
IF en1.frame>1 THEN en1.frame=0
IF en2.frame>1 THEN en2.frame=0
IF en3.frame>1 THEN en3.frame=0
ENDFUNCTION

FUNCTION Init_Game_Objects:

LOCAL Xpos=48
LOCAL Ypos=112
LOCAL Speed
FOR lp=1 TO 1

REPEAT
    Speed=0.1
  UNTIL Speed<>0

SpawnRowOfCharacters(Xpos,Ypos,11)
NEXT

ENDFUNCTION

FUNCTION SpawnRowOfCharacters: Xpos,Ypos,Count

LOCAL space=32

FOR lp=1 TO Count

  en1.enx=Xpos + (space * (lp-1) )
  en1.eny=Ypos
  en1.status=0
  DIMPUSH enemy1[],en1

NEXT

FOR lp=1 TO Count

  en2.enx=Xpos + (space * (lp-1) )
  en2.eny=Ypos+32
  en2.status=0
  DIMPUSH enemy2[],en2

NEXT

FOR lp=1 TO Count

  en2.enx=Xpos + (space * (lp-1) )
  en2.eny=Ypos+64
  en2.status=0
  DIMPUSH enemy2[],en2

NEXT


FOR lp=1 TO Count

  en3.enx=Xpos + (space * (lp-1) )
  en3.eny=Ypos+96
  en3.status=0
  DIMPUSH enemy3[],en3

NEXT

FOR lp=1 TO Count

  en3.enx=Xpos + (space * (lp-1) )
  en3.eny=Ypos+128
  en3.status=0
  DIMPUSH enemy3[],en3

NEXT

ENDFUNCTION

FUNCTION DrawTheScreen:

FOREACH bull IN bullets[]
DRAWSPRITE 1,bull.bulx,bull.buly
NEXT

FOREACH en1 IN enemy1[]
DRAWANIM 2,en1.frame,en1.enx,en1.eny
NEXT

FOREACH en2 IN enemy2[]
DRAWANIM 3,en2.frame,en2.enx,en2.eny
NEXT

FOREACH en3 IN enemy3[]
DRAWANIM 4,en3.frame,en3.enx,en3.eny
NEXT



DRAWANIM 0,0,px,py

SHOWSCREEN

ENDFUNCTION