Bullet collision with enemy is causing a problem.
Posted: Thu Mar 19, 2015 11:15 am
Yeah this is my first post. And the subject might be a little unclear. The problem is that if like three or four "bullets" hit the enemy, the enemy sort of freezes in place instead of just being constantly pushed back. But this is my bullet collide with enemy code:
And in case it's the enemy movement code. Here it is:
Thanks for the help.
Oh, here's the .love
https://www.dropbox.com/s/zhmuhwlqf41iduk/gr.love?dl=0
Code: Select all
[size=85]
function bullet_collision(dt)
for i,v in ipairs(bullet) do
if enemy.x > v.x or
enemy.y < v.y + v.height and
enemy.y > v.y and
enemy.y + enemy.img:getHeight() < v.y and
enemy.y + enemy.img:getHeight() > v.y + v.height then
enemy.y = -100
sound:play()
end
if enemy.y > v.y or
enemy.x < v.x + v.width and
enemy.x > v.x and
enemy.x + enemy.img:getWidth() < v.x and
enemy.x + enemy.img:getWidth() > v.x + v.width then
enemy.y = -100
sound:play()
end
if enemy.y < 0 then
enemy.y = enemy.y + enemy.speed * dt
end
end
end
[/size]
Code: Select all
[size=85]
function enemy_move(dt)
if enemy.y < 0 then
enemy.y = enemy.y + enemy.speed * dt
end
if enemy.y < 720 then
enemy.y = enemy.y + enemy.speed * dt
end
if enemy.y > 720 then
enemy.y = -100
enemy.x = love.math.random(0, 1280)
end
end
[/size]
Oh, here's the .love
https://www.dropbox.com/s/zhmuhwlqf41iduk/gr.love?dl=0