Collision problems with Space Invaders
I have aliens flying about the screen. If they hit the player, the player looses a life. For now, I set the player's Y to 900 which takes him off screen. So, as the code explains, for every monster that is currently alive, does the monster's x/y coordinates equal the player's x/y location. If so, set the player offscreen for now. I noticed the positions have to be "exact" for the PC to loose a life. How can I detect if "any" monster falls into the player's range? I always had trouble with this. Any help would be great.
Code:
// Player colliding into the monsters
for (register int i = 0; i < MAX_MONSTERS; i++) {
if (monster[i].getAlive()) {
if ((monster[i].getX() == PC.getX()) &&
(monster[i].getY() == PC.getY()))
PC.setY(900); // Take player offscreen for now.
}
}