Original Post
hi guys, im new here, and new to game programming too. Anyway, my code for a 2d shooter game Im making is having problems with the collision. Here is the function im having problems with:
;moves the bullets and detects collision
Function UpdateBullets()
;check every bullet
For bullet.bullet = Each bullet
;check if the bullet is from the player
If bullet\from = 1
;if player is facing right
If player\direction = MRIGHT
;move the bullet right
bullet\x = bullet\x + 20
EndIf
;if player is facing left
If player\direction = MLEFT
;move the bullet left
bullet\x = bullet\x - 20
EndIf
;End "if bullet\from = 1"
EndIf
;check if the bullet is from the enemy
If bullet\from = 2
;move the bullet left
bullet\x = bullet\x - 20
EndIf
;If bullet is from the player then draw the correct image
If bullet\from = 1
DrawImage (bulletimage, bullet\x, bullet\y)
Else
DrawImage (bulletsimage,bullet\x, bullet\y)
EndIf
;if the bullet is from the player
If bullet\from = 1
;CHECK EVERY ENEMY!
For tank.tank = Each tank
;check to see that the player's bullet and the enemy collided
If ImagesCollide(bulletimage, bullet\x, bullet\y, 0, tankimage,tank\x,tank\y,0)
;subtract a hitpoint
tank\hits = tank\hits - 1
;if there are no hitpoints left delete enemy
If tank\hits <= 0
Delete tank
EndIf
;and the bullet
Delete bullet
EndIf
Next
EndIf
;if the bullet is from an enemy
If bullet\from = 2
;and the player and enemy's bullet collide
If Imagescollide(bimage,bullet\x,bullet\y,0,playerimage,player\x,player\y,0)
;subtract a hitpoint
player\hits = player\hits - 1
;if the player's hits = 0 delete the player
If player\hits <= 0
Delete player
;end the program
End
EndIf
EndIf
;delete the bullet if it collided
Delete bullet
EndIf
Next
End Function When I run the program, it highlights this: If Imagescollide(bimage,bullet\x,bullet\y,0,playerimage,player\x,player\y,0) and says "object does not exist". Keep in mind this is not the entire game. it is just 1 function. Thanks in advance. [Edited by - Fruny on August 25, 2005 10:45:43 AM]