I am creating a clone of Space Invaders in XNA as an exercise. I’ve hit various snags over the past 5 days, especially with the collisions which I have worked around. I’ve finally got it working only to hit another issue.
The bullet from the player collides and destroys the invaders, however, the rectangle I create as a hitbox for the collisions remains. (I think)
Whole solution can be located here so you can recreate the issue just press F5, and spacebar to kill the green invaders, the blank space that is left behind I believe is the rectangle.: https://www.dropbox.com/sh/pzy7fx3tuprzza2/GIjhZ6V5ll
My question is: When that bullet hits the invader, how can I remove the rectangle too, or stop them intersecting.
The issue seems to be that your aren’t recognizing that your invader has been blown up on line 524 of Game1.cs You have a FOR statement that spins through your invaders, figures out where the invader should be, and then checks if the hit boxs intersect. You do not check to see if that invader whose hitbox is intersect is infact already dead.
In your Invaders object (Invader1, Invader2, etc) you need to keep track of a variable to determine if the Invarder is alive. It appears you might be able to use the variable invaderVis if you like since that seems to determine if you should show that invader.
So line 524 should be change to something like
Also change your UFO hit checker on lne 539 to do the same as well.