Add collision asteroid

This commit is contained in:
Andros Fenollosa 2016-12-03 23:00:36 +01:00
parent bc036967fb
commit b8ffe7ed05

View File

@ -29,7 +29,7 @@ function asteroids.update(dt, game)
for key, asteroid in pairs(asteroids.bodys) do
if asteroid.x + asteroid.img:getWidth() < 0 then
table.remove(asteroids.bodys, key)
game.collisions:remove('asteroid' .. key)
remove_collision(key, game)
end
end
-- Create asteroids
@ -57,6 +57,7 @@ function make_asteroid(pos, game, x_random)
asteroids.bodys[pos].x = math.random(0, game.canvas.width - temp_img:getWidth())
end
-- Collision
remove_collision(pos, game)
game.collisions:add(
'asteroid' .. pos,
asteroids.bodys[pos].x,
@ -66,4 +67,10 @@ function make_asteroid(pos, game, x_random)
)
end
function remove_collision(pos, game)
if game.collisions:hasItem('asteroid' .. pos) then
game.collisions:remove('asteroid' .. pos)
end
end
return asteroids