The wrong enemy disappears when I shoot it

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Eclectic
Prole
Posts: 2
Joined: Mon Jan 20, 2014 9:37 pm

The wrong enemy disappears when I shoot it

Post 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
Last edited by Eclectic on Tue Jan 21, 2014 12:57 pm, edited 1 time in total.
Gravy
Citizen
Posts: 80
Joined: Sun Jan 22, 2012 10:15 pm
Location: CA, USA

Re: The wrong enemy disappears when I shoot it

Post by Gravy »

Uhh, I think the problem is that your code is racist. Line 71. What the fuck?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: The wrong enemy disappears when I shoot it

Post 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.)
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: The wrong enemy disappears when I shoot it

Post 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)
Eclectic
Prole
Posts: 2
Joined: Mon Jan 20, 2014 9:37 pm

Re: The wrong enemy disappears when I shoot it

Post 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.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Re: The wrong enemy disappears when I shoot it

Post by Chroteus »

That Line 71... That was unexpected to see such stuff in a source code of a game. :rofl:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests