Page 1 of 1

The wrong enemy disappears when I shoot it

Posted: Mon Jan 20, 2014 9:43 pm
by Eclectic
So i wanted to get into this and stuff so i followed Headchants tutorial on how to make a space invaders clone.
It was a meager success, i can move the player around, the enemies move. However when i shoot an enemy
another goes. Its really weird and I dont know how to fix it yet know what is going wrong because i learned nothing from the tutorial.
So if anybody could help me figure out what is going wrong and maybe point me to a better tutorial i will be happy.

Heres the code so far: http://pastebin.com/eM8wHJZn

Re: The wrong enemy disappears when I shoot it

Posted: Tue Jan 21, 2014 7:00 am
by Gravy
Uhh, I think the problem is that your code is racist. Line 71. What the fuck?

Re: The wrong enemy disappears when I shoot it

Posted: Tue Jan 21, 2014 8:10 am
by Plu
Which one is disappearing? I'm assuming it isn't random; knowing which one goes is probably the first step to figuring it out :)

(If it's the one directly to the left or right of the hit one, you're probably suffering an offset problem or doing something wrong in detecting the collision.)

Re: The wrong enemy disappears when I shoot it

Posted: Tue Jan 21, 2014 9:01 am
by micha
The problem with removing entries from is table is that the other entries get rearranged every time. So if you have a list of indices and remove one of them, then the following indices are not correct anymore.

Solve this by traversing the table backwards (make sure the indices in the list of dead enemies is decreasing)

Re: The wrong enemy disappears when I shoot it

Posted: Tue Jan 21, 2014 12:58 pm
by Eclectic
Whoops i dont know how that ended up in my code, fixed the rather expletitive comments. I have nothing against different ethnicities, but apparently my alcohol triggered alter-ego does. Fahk. New link in the OP for you guys.

Re: The wrong enemy disappears when I shoot it

Posted: Thu Jan 23, 2014 1:46 pm
by Chroteus
That Line 71... That was unexpected to see such stuff in a source code of a game. :rofl: