Page 1 of 1

Divebombing foes, more collision stuff

Posted: Mon Jul 30, 2012 1:02 am
by GungnirDev
Now that I've figured out how to make my bullets and enemies mutually remove themselves from the world I've decided to try the same thing with my new divebombing enemy type (which looks a tad like Pac-Man cosplaying as Wolverine) and and the player.

Main question: Why isn't my collision working? All I get out of this (in ship.lua) is that now killing one enemy will also also kill another enemy next to the first enemy, which doesn't seem right, and they still can't kill the player's ship. Could someone please explain for future reference why my current code doesn't remove player and enemy? The code is the same it's just the targets that are different.

Secondary question: I want the divebomber enemies to zig-zag as they falls. Easiest way to do this?

Re: Divebombing foes, more collision stuff

Posted: Mon Jul 30, 2012 3:00 am
by Santos
Try removing lines 68 to 75 in ship.lua.

Code: Select all

-- remove the marked enemies
for i,v in ipairs(remEnemy) do
	table.remove(enemies, v)
end

for i,v in ipairs(remShot) do
	table.remove(player.shots, v)
end
Otherwise things get removed twice (again on lines 90 to 96). :D

Re: Divebombing foes, more collision stuff

Posted: Mon Jul 30, 2012 6:58 am
by kalium
Secondary question: I want the divebomber enemies to zig-zag as they falls. Easiest way to do this?
You could try using a sine function to control the enemies' horizontal positions.

Something like

Code: Select all

posX = initialX + math.sin(time);
time = time + dt;
Where 'time' is the total time in the game, initialX is the 'central' position of the ondulation, and dt is the time variation between frames.
Multiply 'dt' by a factor to define how fast he zigzags.

Re: Divebombing foes, more collision stuff

Posted: Mon Jul 30, 2012 9:12 pm
by GungnirDev
@ kalium: It worked! Thanks, I'll play with this a bit. EDIT: sin was too big, so I used cos instead.

@ Santos: That fixed the multiple-kill problem, but the enemies still can't remove the player.