I have the following code to check whether a series of sprite numbers (4 to 10) are colliding with a bullet. This code is ran whenever one or more bullets are on the screen:
for bullets = 1 to 25
for spr_no = 4 to 10
if sprite exist(spr_no)
if CheckBulletEnemyCollision(bullets,spr_no) = true
print "ENEMY KILLED"
endif
else
print "sprite number ",spr_no," doesn't exist"
endif
next spr_no
next bullets
The bullets are not sprites themselves but basic 2D lines that DB draws. Their properties (x, y and speed) are held in an array. I have a function called "CheckBulletEnemyCollision()" that checks whether the position of the bullet matches that of the sprite number that is passed into it.
This works as expected the first time the enemy is on the screen, i.e. it says enemy killed when a bullet collides with it. But the second/third etc. time the enemy sprites are on the screen the code returns "sprite number ... doesn't exist"
Why could this be. Could it be because when the enemy is off screen I destroy the sprite? This crossed my mind but when the enemy is due to come back on screen I use the "sprite 4,x,y,imagenumber" command therefore re-making the sprite and making it "exist".
Is there a problem with the sprite exists function, or with my code? Thanks for anyones help.
Cheers,
Jibbed.
PS. Lee Bamber is actually teaching me this stuff in uni at the mo but haven't had a chance to ask him yet