deletes bullets after bouncing so many times

main
Simon Kellet 5 months ago
parent f8d71bb27d
commit b8106bc1aa
  1. 36
      Game/UpdateGame.lua

@ -39,6 +39,14 @@ function UpdateGame(dt)
for i, v in ipairs(Bullets1) do
v:update(dt)
-- Check bounce count
if v.bounce >= _G.BULLETS_BOUNCE_MAX then
table.remove(Bullets1, i)
v.collider:destroy()
end
-- Handle screen edges
if v.y < 0 then --top of screen
table.remove(Bullets1, i)
v.collider:destroy()
@ -46,6 +54,8 @@ function UpdateGame(dt)
table.remove(Bullets1, i)
v.collider:destroy()
end
-- Hit player2
if v.collider:enter("Player2") then
print("Player1 hit Player2!")
table.remove(Bullets1, i)
@ -55,6 +65,7 @@ function UpdateGame(dt)
end
end
-- Hit player1
if v.collider:enter("Player1") then
print("Player 1 hit themselves!")
table.remove(Bullets1, i)
@ -63,10 +74,24 @@ function UpdateGame(dt)
UserPlayer1.health = UserPlayer1.health - 1
end
end
--Hit another bullet
if v.collider:enter("Bullet1") then
table.remove(Bullets1, i)
v.collider:destroy()
end
end
for i, v in ipairs(Bullets2) do
v:update(dt)
-- Check bounce count
if v.bounce >= _G.BULLETS_BOUNCE_MAX then
table.remove(Bullets2, i)
v.collider:destroy()
end
-- Handle screen edges
if v.y < 0 then --top of screen
table.remove(Bullets2, i)
v.collider:destroy()
@ -75,6 +100,7 @@ function UpdateGame(dt)
v.collider:destroy()
end
-- Hit player2
if v.collider:enter("Player1") then
print("Player2 hit Player1!")
table.remove(Bullets2, i)
@ -83,16 +109,24 @@ function UpdateGame(dt)
UserPlayer2.health = UserPlayer2.health - 1
end
end
-- Hit player1
if v.collider:enter("Player2") then
print("Player 2 hit themselves!")
table.remove(Bullets2, i)
v.collider:destroy()
if UserPlayer2.health > 0 then
UserPlayer2.health = UserPlayer2.health - 1
end
end
--Hit another bullet
if v.collider:enter("Bullet2") then
table.remove(Bullets2, i)
v.collider:destroy()
end
end
UserPlayer1:handleKeys("w", "s", "a", "d", dt)
UserPlayer2:handleKeys("up", "down", "left", "right", dt)
UserPlayer1:updateCol()

Loading…
Cancel
Save