2 types colliding

Blitz3D Forums/Blitz3D Beginners Area/2 types colliding

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

Nah, types are super fast. You'll need to do two loops to check every collision. Unless your talking about 100's of bullets vs hundreds of ships, doing 2 loops is fine for speed really :o)

If possible, you can use the ImagesOverlap command. It's faster than the ImagesCollide command.