Help - Type problem

Previous topic - Next topic

PeeJay

I'm sure this is just me being stupid, but I have a problem with the following code that I can't figure out.

It is code to do a collision detection between shots fired and enemies

Code (glbasic) Select
FOREACH en IN enemies[]
LOCAL enemyhit=FALSE
FOREACH sh IN shots[]
IF SPRCOLL (2,sh.x,sh.y,3,en.x,en.y)
DELETE sh
enemyhit=TRUE
ENDIF
NEXT
IF enemyhit=TRUE
DELETE en
ENDIF
NEXT
When run, the shots are being deleted okay, but the enemies are not. Anyone know why?!?
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Moru

After a delete command, the code under it gets skipped and the loop continues from the top again. Always use delete at the end of the loop if you expect it to execute the rest.

Try moving the Delete command under enemyhit=TRUE

PeeJay

Ah, thanks for that Moru - I knew it mush have been me being stupid :)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity