I am writing my first game (a pretty poor space invaders). When the players ship fires a bullet (of which there may be lots on the screen at the same time) how do I detect if ANY bullet has hit ANY alien without doing 2 loops which slow down the program too much (i.e. looping through every bullet and every alien) - I have looked through the forum and may be missing the answer. The collision function I've used is below.
Thanks for any help.
Function CheckCollision()
For bullet = Each bulletdata
For alien = Each aliendata
If Imagescollide(bullets,bullet\xpos,bullet\ypos,Aliens,Alien\xpos,Alien\ypos) Then
PlaySound Alienhit
score = score + 20
Delete Alien
EndIf
Next
Next
End Function
Thanks for any help.
Function CheckCollision()
For bullet = Each bulletdata
For alien = Each aliendata
If Imagescollide(bullets,bullet\xpos,bullet\ypos,Aliens,Alien\xpos,Alien\ypos) Then
PlaySound Alienhit
score = score + 20
Delete Alien
EndIf
Next
Next
End Function