You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
love2d-tank/Game/UpdateGame.lua

76 lines
1.7 KiB

7 months ago
function UpdateGame(dt)
6 months ago
--WindField
World:update(dt)
7 months ago
local max = math.max
6 months ago
7 months ago
KeyPressTime1 = max(0, KeyPressTime1 - dt)
if KeyPressTime1 <= 0 then
EnableKeyPress1 = true
end
KeyPressTime2 = max(0, KeyPressTime2 - dt)
if KeyPressTime2 <= 0 then
EnableKeyPress2 = true
end
for i, v in ipairs(Bullets1) do
v:update(dt)
if v.y < 0 then --top of screen
table.remove(Bullets1, i)
v.collider:destroy()
elseif v.y > love.graphics.getHeight() then --bottom of screen
table.remove(Bullets1, i)
v.collider:destroy()
end
if v.collider:enter("Player2") then
6 months ago
print("Player1 hit Player2!")
table.remove(Bullets1, i)
v.collider:destroy()
if UserPlayer1.health > 0 then
UserPlayer1.health = UserPlayer1.health - 1
end
end
if v.collider:enter("Player1") then
print("Player 1 hit themselves!")
7 months ago
table.remove(Bullets1, i)
v.collider:destroy()
6 months ago
if UserPlayer1.health > 0 then
UserPlayer1.health = UserPlayer1.health - 1
end
7 months ago
end
end
for i, v in ipairs(Bullets2) do
v:update(dt)
if v.y < 0 then --top of screen
table.remove(Bullets2, i)
v.collider:destroy()
elseif v.y > love.graphics.getHeight() then --bottom of screen
table.remove(Bullets2, i)
v.collider:destroy()
end
if v.collider:enter("Player1") then
6 months ago
print("Player2 hit Player1!")
7 months ago
table.remove(Bullets2, i)
v.collider:destroy()
6 months ago
if UserPlayer2.health > 0 then
UserPlayer2.health = UserPlayer2.health - 1
end
end
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
7 months ago
end
end
UserPlayer1:update(dt)
UserPlayer2:update(dt)
end