ok so i started trying to make a game again because i've been making other stuff for a while and so ithought i'd start with space invaders.
well i have shooting and i know how i'm gunna do collision. its just the enemies. welli think i know how i'm going to do it but what do you thing about this approach?
i have a editor where you edit "Frames" for where the enemy moves then you save Stages and save those stages into a level. and each frame has the x and y for every enemy in it. then i can just load in the final level text file and use the stages and frames as i need them.
i havn't thought about the enemies shooting yet though.
Heres the game part
remstart
-------------------------------------------------------------------
program name:
-------------------------------------------------------------------
written by: Caleb Stewart
date:
-------------------------------------------------------------------
comments:
-------------------------------------------------------------------
remend
Sync on
Sync rate 0
Set window on
Set window position 160,120
LoadImages()
Global Player
Global Enemy
Global Bullet
Player = 2
Enemy = 1
BulletI = 3
Dim Grid(30,30)
Dim Bullet(30)
Dim BulletData(100,5)
Grid(0,0)=96
Grid(1,0)=0
For X=1 to 30 step 1
Grid(0,X)=Grid(0,X-1)+32
Grid(1,X)=Grid(1,X-1)+32
next x
Do
Ink rgb(255,255,255),0
line grid(0,0),0,Grid(0,0),479
line grid(0,14),0,Grid(0,14),479
sprite Player,Grid(0,PX),Grid(1,PY),player
set sprite player,0,1
If rightkey() and press=0 and px<13 Then PX=PX+1 : press=1
if leftkey() and Press=0 and PX>0 then px=px-1 : Press=1
IF upkey() and press=0 and PY>0 then py=py-1 : press=1
If downkey() and press=0 and py<14 then py=py+1 : press=1
If leftkey()=0 and Rightkey()=0 and upkey()=0 and downkey()=0 then press=0
If Spacekey()
Bullet=FindFreeBullet()
If Bullet>0
if auto=1 and timer()-counter>10
Bullet(Bullet)=1
BulletData(Bullet,0)=Grid(0,PX)
BulletData(Bullet,1)=Grid(1,PY)
counter=0
endif
If Auto=0 and skey=0
Bullet(Bullet)=1
BulletData(Bullet,0)=Grid(0,PX)
BulletData(Bullet,1)=Grid(1,PY)
Skey=1
endif
endif
endif
If keystate(45)=1 and Adown=0 and auto=0 then auto=1 : adown=1
If keystate(45)=1 and ADown=0 and Auto=1 then Auto=0 : adown=1
If keystate(45)=0 then adown=0
Text 0,0,"Automatic: " + Str$(Auto)
if spacekey()=0 then skey=0
Gosub HandleBullets
Counter=Counter+Timer()
Sync
Cls
Loop
HandleBullets:
For X=2 to 30
If Bullet(X)=1
if bulletdata(X,1)>-1
Sprite X+99,BulletData(X,0),BulletData(X,1),BulletI
If timer()-bulletcounter>5
if Bulletdata(X,1)>0
bulletcounter=0
BulletData(X,1)=Bulletdata(X,1)-2
else
Bullet(X)=0
delete sprite X+99
endif
endif
endif
endif
next x
BulletCounter=BulletCounter+Timer()
return
Function LoadImages()
Load Image "Sprites/Invadersprites.bmp",100
Paste image 100,0,0
Get image 1,0,0,32,32
Get image 2,32,0,64,32
Get image 3,64,0,96,32
cls
endfunction
Function UpdateBulletPositions()
For X=1 to 30
IF bullet(X)=1
If Bulletdata(X,1)>0
BulletData(X,1)=BulletData(X,1)-1
else
endif
endif
next x
endfunction
Function findfreebullet()
For X=2 to 30
If bullet(X)=0 then exitfunction X
next x
endfunction 0
And the editor (very far from done lol)
remstart
-------------------------------------------------------------------
program name: Invaders Ai Editor
-------------------------------------------------------------------
written by: Caleb Stewart
date:
-------------------------------------------------------------------
comments:
-------------------------------------------------------------------
remend
Sync on
Sync rate 0
WinX=(640/2)/2+25
WinY=(480/2)/2+25
Set window on
Set window position WinX,WinY
If file exist("Keyframes.ai") then delete file "Keyframes.ai"
Open to write 1,"Keyframes.AI"
Global Keyframe
Global EnemyNum
Dim AI(10,1)
Dim Map(1,14)
dim Array$(1000)
map(0,0)=96
Map(1,0)=0
For X=1 to 14
Map(0,X)=Map(0,X-1)+32
Map(1,X)=Map(1,X-1)+32
next x
Load image "Sprites/InvaderSprites.bmp",100
Paste image 100,0,0
Get image 1,0,0,32,32
delete image 100
cls
DrawGrid()
Do
Paste image 2,96,0
For Y=0 to 14
for X=0 to 13
If mouse_inside(Map(0,X),Map(1,Y),Map(0,X)+32,Map(1,Y)+32)=1
If mouseclick()
if enemynum<10 and MC=0
Paste image 1,Map(0,X),Map(1,Y)
AI(EnemyNum,0)=X
AI(EnemyNum,1)=Y
Enemynum=enemynum+1
Get image 2,96,0,544,480
mc=1
endif
else
mc=0
endif
endif
next x
next y
if keystate(46)=1
cls rgb(0,0,0)
DrawGrid()
For X=0 to enemynum
AI(X,0)=0
AI(X,1)=0
next x
Enemynum=0
endif
IF mouseclick() and mouse_inside(10,10,85,30)=1
MakeButton(10,10,"Save frame",1)
repeat : sync : until Mouseclick()=0
For X=0 to enemynum-1
Write string 1,"Enemy " + str$(X+1)
Write string 1,Str$(AI(X,0))
Write string 1,Str$(AI(X,1))
next x
cls RGB(0,0,0)
DrawGrid()
For X=0 to enemynum
AI(X,0)=0
AI(X,1)=0
next x
Enemynum=0
keyframe=keyframe+1
else
MakeButton(10,10,"Save frame",0)
endif
If mouseclick() and mouse_inside(10,35,85,55)=1
Makebutton(10,35,"Save Stage",1)
Repeat : Sync : Until Mouseclick()=0
Close file 1
Copy file "Keyframes.ai","Stage " + Str$(stage) + ".txt"
Stage=Stage+1
Delete file "keyframes.Ai"
Open to write 1,"Keyframes.ai"
cls RGB(0,0,0)
DrawGrid()
For X=0 to enemynum
AI(X,0)=0
AI(X,1)=0
next x
Enemynum=0
keyframe=0
else
Makebutton(10,35,"Save Stage",0)
endif
If mouseclick() and mouse_inside(10,60,85,80)=1
MakeButton(10,60,"Save Level",1)
repeat : sync : until mouseclick()=0
Open to write 2,"Level.txt"
For X=0 to Stage+1
LoadStage()
Write string 2,"Stage " + Str$(X)
For X=0 to 1000
If Array$(X)>""
Write string 2,Array$(X)
endif
next x
next x
else
MakeButton(10,60,"Save Level",0)
endif
Sync
Cls RGB(192,192,192)
Loop
Function DrawGrid()
ink rgb(255,255,255),0
For Y=0 to 14
for X=0 to 13
Line Map(0,X),Map(1,Y),Map(0,X)+32,Map(1,Y)
Line Map(0,X),Map(1,Y),Map(0,X),Map(1,Y)+32
Line Map(0,X),Map(1,Y)+32,Map(0,X)+32,Map(1,Y)+32
Line Map(0,X)+32,Map(1,Y),Map(0,X)+32,Map(1,Y)+32
next x
next y
Line 543,0,543,479
line 96,479,543,479
Get image 2,96,0,544,480
endfunction
Function Mouse_inside(X,Y,W,D)
if mouseX()>X and MouseX()<W
If mouseY()>Y and MouseY()<D
exitfunction 1
endif
endif
endfunction -1
Function MakeButton(X,Y,Txt$,Press)
Width = Len(txt$)*5+20
If press=0
ink rgb(255,255,255),0
Line X,Y,X+Width,Y
Line X,Y,X,Y+20
Ink rgb(0,0,0),0
Line X+width,Y,X+width,Y+20
line X,Y+20,X+Width,Y+20
Text X+5,Y,Txt$
else
ink rgb(0,0,0),0
Line X,Y,X+Width,Y
Line X,Y,X,Y+20
Ink rgb(255,255,255),0
Line X+width,Y,X+width,Y+20
line X,Y+20,X+Width,Y+20
ink rgb(0,0,0),0
Text X+5,Y,Txt$
endif
endfunction
and i attached the images.
New Site! Check it out \/