In this program the problem starts when I shoot a bullet from the cyclops and it hits a block. Sometimes the block and bullet disappear. Most of the time it gives me the Image does not exist error. I'm pretty sure this is a type problem. The cause of the problem, I believe, is in the last function at the very bottom of the code. All help is appreciated. :)
Graphics 640,400
;constant variables that won't change
Const uparrow = 200
Const downarrow = 208
Const leftkey = 203
Const rightkey = 205
Const spacebar = 57
;______________Images-----------------
Global stickmancyclops = LoadImage("StickmanCyclops.bmp") ;the stickman cyclops himself...
MaskImage stickmancyclops,0,0,0
Global bulletimage = LoadImage("bullet.bmp")
MaskImage bulletimage,0,0,0
Global BlockImage = LoadImage("block.bmp")
MaskImage BlockImage,0,0,0
;______________Types------------------
Type CyclopsType
Field x,y
End Type
Type BulletType
Field x,y
End Type
Type BlockType
Field x,y
End Type
;------------------------------------
Global cyclops.CyclopsType = New CyclopsType
cyclops\x = 50
cyclops\y = 50
Global BlockSpawnRate = 0
SetBuffer BackBuffer()
SeedRnd MilliSecs
;--------------------MAIN LOOP---------------------
While Not KeyDown(1)
BlockSpawnRate = BlockSpawnRate + 1
Cls
DrawImage stickmancyclops,cyclops\x,cyclops\y
MoveCyclops() ; the function that moves the stickman cyclops...
CreateBallandBlock()
UpdateBallandBlock()
Flip
Wend
;-------------END OF MAIN LOOP----------------
Function MoveCyclops();moves the STICKMAN CYCLOPS!
If KeyDown(leftkey) Then cyclops\x = cyclops\x - 3
If KeyDown(rightkey) Then cyclops\x = cyclops\x + 3
If KeyDown(uparrow) Then cyclops\y = cyclops\y - 3
If KeyDown(downarrow) Then cyclops\y = cyclops\y + 3
End Function
;FUNCTION WHICH CREATES THE BULLETS AND BLOCKS
Function CreateBallandBlock()
If KeyHit(spacebar)
bullet.BulletType = New BulletType
bullet\x = cyclops\x + 316
bullet\y = cyclops\y + 28
EndIf
If BlockSpawnRate >= 120
block.blocktype = New BlockType
block\x = Rand(1,200)
block\y = Rand(1,200)
EndIf
If BlockSpawnRate >= 120 Then BlockSpawnRate = 0
End Function
;FUNCTION WHICH UPDATES THE BULLETS AND BALLS
Function UpdateBallandBlock()
For bullet.bullettype = Each bullettype
bullet\y = bullet\y - 4
DrawImage BulletImage,bullet\x,bullet\y
For block.blocktype = Each blocktype
If ImagesCollide(blockimage,block\x,block\y,0,bulletimage,bullet\x,bullet\y,0)
Delete block
Delete bullet
EndIf
Next
Next
For block.blocktype = Each blocktype
DrawImage blockimage,block\x,block\y
Next
End Function
|