The attached is a simple space invader type game (not complete !!) based on the SPIDER example that comes with BB. None of the spiders move or shoot and I limit it to 3 bullets from my ship maximum on the screen at a time. So WHY is it so slow - the ship crawls along the bottom , the bullets are slow and none os the spiders disappear when hit? I think the problem may be in the checkcollision routine but not sure. Can anyone point me in the right direction? Thanks in advance
Graphics 640,480,0,1
SetBuffer BackBuffer()
Type AlienData
Field xpos, ypos
End Type
Type BulletData
Field xpos,ypos
End Type
Const Alien_ypos_Start = 460
Const Alien_Anim_Pause = 4
Global Aliens = LoadImage("c:/Program Files/BlitzPlus/COURSE/AlienShapes.bmp")
Global Player = LoadImage("c:/Program Files/BlitzPlus/COURSE/Player.bmp")
Global Bullets = LoadImage("c:/Program Files/BlitzPlus/COURSE/Bullet.bmp")
Global shotgun = LoadSound("c:/Program Files/BlitzPlus/COURSE/shotgun.wav")
Global Alienhit = LoadSound("c:/Program Files/BlitzPlus/COURSE/toyduck.wav")
Global logo = LoadImage("c:/Program Files/BlitzPlus/COURSE/Alienlogo_small.bmp")
Global theend = LoadImage("c:/Program Files/BlitzPlus/COURSE/game_over.bmp")
Global score = 0
Global Alien.AlienData
Global Bullet.BulletData
Global GameOver = False
Global Playerxpos = 320
Global Playerypos = 360
Global livebullets =0
SoundPan Alienhit,-1
SoundPan shotgun,1
;IntroScreen()
InitAlien()
Repeat
If GameOver = True Then
GameoverScreen()
InitAlien()
GameOver = False
score = 0
Else
DrawScreen()
DrawEnemies()
DrawShip()
DrawBullets()
checkcollision()
Flip
EndIf
Until KeyDown(1)
TerminateProgram()
Function InitAlien()
For tempy=1 To 3
For tempx=1 To 10
Alien.AlienData = New AlienData
Alien\xpos = 40+tempx*50
Alien\ypos = tempy*40
Next
Next
End Function
Function GameoverScreen()
ClearScreens()
SetBuffer FrontBuffer()
DrawImage theend,50,80
Color 255,255,255
Text 200,200,"You reached a score of "+score
Text 300,310,"Press spacebar to continue",1,1
Repeat
Until KeyDown(57)
ClearScreens()
End Function
Function DrawScreen()
Viewport 0,0,640,480
Cls
Color 255,255,255
Text 0,0,"Score "+score
Color 0,255,0
Line 0,399,640,399
Line 0,15,640,15
Viewport 0,15,640,385
End Function
Function TerminateProgram()
FreeSound shotgun
FreeSound Alienhit
FreeImage Aliens
FreeImage logo
FreeImage theend
End
End Function
Function DrawEnemies()
For Alien = Each AlienData
DrawImage Aliens,Alien\xpos,Alien\ypos
Next
End Function
Function CheckCollision()
For bullet = Each bulletdata
For alien = Each aliendata
If ImagesOverlap(bullets,bullet\xpos,bullet\ypos,Aliens,Alien\xpos,Alien\ypos) Then
PlaySound Alienhit
score = score + 1000
Delete Alien
EndIf
Next
Next
If score Mod 10 = 0 Then InitAlien()
End Function
Function DrawShip()
DrawImage Player, Playerxpos, Playerypos
If KeyDown(205) Then playerxpos=playerxpos+1
If KeyDown(203) Then playerxpos=playerxpos-1
End Function
Function DrawBullets()
If KeyHit(57) And livebullets<3 Then
livebullets=livebullets+1
Bullet.BulletData = New BulletData
Bullet\xpos = playerxpos+10
Bullet\ypos = 350
PlaySound shotgun
EndIf
For Bullet = Each BulletData
DrawImage Bullets, Bullet\xpos, Bullet\ypos
Bullet\ypos=bullet\ypos-8
If bullet\ypos<0 Then
livebullets=livebullets-1
Delete bullet
EndIf
Next
End Function
Function ClearScreens()
Viewport 0,0,640,480
SetBuffer FrontBuffer()
Cls
SetBuffer BackBuffer()
Cls
End Function
Graphics 640,480,0,1
SetBuffer BackBuffer()
Type AlienData
Field xpos, ypos
End Type
Type BulletData
Field xpos,ypos
End Type
Const Alien_ypos_Start = 460
Const Alien_Anim_Pause = 4
Global Aliens = LoadImage("c:/Program Files/BlitzPlus/COURSE/AlienShapes.bmp")
Global Player = LoadImage("c:/Program Files/BlitzPlus/COURSE/Player.bmp")
Global Bullets = LoadImage("c:/Program Files/BlitzPlus/COURSE/Bullet.bmp")
Global shotgun = LoadSound("c:/Program Files/BlitzPlus/COURSE/shotgun.wav")
Global Alienhit = LoadSound("c:/Program Files/BlitzPlus/COURSE/toyduck.wav")
Global logo = LoadImage("c:/Program Files/BlitzPlus/COURSE/Alienlogo_small.bmp")
Global theend = LoadImage("c:/Program Files/BlitzPlus/COURSE/game_over.bmp")
Global score = 0
Global Alien.AlienData
Global Bullet.BulletData
Global GameOver = False
Global Playerxpos = 320
Global Playerypos = 360
Global livebullets =0
SoundPan Alienhit,-1
SoundPan shotgun,1
;IntroScreen()
InitAlien()
Repeat
If GameOver = True Then
GameoverScreen()
InitAlien()
GameOver = False
score = 0
Else
DrawScreen()
DrawEnemies()
DrawShip()
DrawBullets()
checkcollision()
Flip
EndIf
Until KeyDown(1)
TerminateProgram()
Function InitAlien()
For tempy=1 To 3
For tempx=1 To 10
Alien.AlienData = New AlienData
Alien\xpos = 40+tempx*50
Alien\ypos = tempy*40
Next
Next
End Function
Function GameoverScreen()
ClearScreens()
SetBuffer FrontBuffer()
DrawImage theend,50,80
Color 255,255,255
Text 200,200,"You reached a score of "+score
Text 300,310,"Press spacebar to continue",1,1
Repeat
Until KeyDown(57)
ClearScreens()
End Function
Function DrawScreen()
Viewport 0,0,640,480
Cls
Color 255,255,255
Text 0,0,"Score "+score
Color 0,255,0
Line 0,399,640,399
Line 0,15,640,15
Viewport 0,15,640,385
End Function
Function TerminateProgram()
FreeSound shotgun
FreeSound Alienhit
FreeImage Aliens
FreeImage logo
FreeImage theend
End
End Function
Function DrawEnemies()
For Alien = Each AlienData
DrawImage Aliens,Alien\xpos,Alien\ypos
Next
End Function
Function CheckCollision()
For bullet = Each bulletdata
For alien = Each aliendata
If ImagesOverlap(bullets,bullet\xpos,bullet\ypos,Aliens,Alien\xpos,Alien\ypos) Then
PlaySound Alienhit
score = score + 1000
Delete Alien
EndIf
Next
Next
If score Mod 10 = 0 Then InitAlien()
End Function
Function DrawShip()
DrawImage Player, Playerxpos, Playerypos
If KeyDown(205) Then playerxpos=playerxpos+1
If KeyDown(203) Then playerxpos=playerxpos-1
End Function
Function DrawBullets()
If KeyHit(57) And livebullets<3 Then
livebullets=livebullets+1
Bullet.BulletData = New BulletData
Bullet\xpos = playerxpos+10
Bullet\ypos = 350
PlaySound shotgun
EndIf
For Bullet = Each BulletData
DrawImage Bullets, Bullet\xpos, Bullet\ypos
Bullet\ypos=bullet\ypos-8
If bullet\ypos<0 Then
livebullets=livebullets-1
Delete bullet
EndIf
Next
End Function
Function ClearScreens()
Viewport 0,0,640,480
SetBuffer FrontBuffer()
Cls
SetBuffer BackBuffer()
Cls
End Function