65 lines
1.5 KiB
Lua
65 lines
1.5 KiB
Lua
function CheckHealth(p1, p2)
|
|
if p1.health == 0 then
|
|
HasP2Won = true
|
|
elseif p2.health == 0 then
|
|
HasP1Won = true
|
|
end
|
|
end
|
|
|
|
function updateGame(dt)
|
|
--add delay between key presses
|
|
KeyPressTime1 = math.max(0, KeyPressTime1 - dt)
|
|
if KeyPressTime1 <= 0 then
|
|
EnableKeyPress1 = true
|
|
end
|
|
|
|
KeyPressTime2 = math.max(0, KeyPressTime2 - dt)
|
|
if KeyPressTime2 <= 0 then
|
|
EnableKeyPress2 = true
|
|
end
|
|
|
|
TimeToPlaceWall = TimeToPlaceWall - dt
|
|
if TimeToPlaceWall <= 0 then
|
|
--place a wall at a random location
|
|
local ranx = love.math.random(100, 1000)
|
|
local rany = love.math.random(100, 600)
|
|
local ranw = love.math.random(100, 500)
|
|
local ranh = love.math.random(20, 80)
|
|
local lifetime = love.math.random(4, 10)
|
|
local wall = Wall(ranx, rany, ranw, ranh, lifetime)
|
|
table.insert(Walls, wall)
|
|
TimeToPlaceWall = TIMER --reset the timer
|
|
end
|
|
|
|
-- Walls Updates
|
|
for i, v in ipairs(Walls) do
|
|
v:update(dt)
|
|
end
|
|
|
|
-- Check the players health
|
|
CheckHealth(UserPlayer1, UserPlayer2)
|
|
|
|
-- Bullets Updates
|
|
for i, v in ipairs(Bullets1) do
|
|
v:update(dt)
|
|
if v.y < 0 then --top of screen
|
|
table.remove(Bullets1, i)
|
|
elseif v.y > love.graphics.getHeight() then --bottom of screen
|
|
table.remove(Bullets1, i)
|
|
end
|
|
end
|
|
|
|
for i, v in ipairs(Bullets2) do
|
|
v:update(dt)
|
|
if v.y < 0 then --top of screen
|
|
table.remove(Bullets2, i)
|
|
elseif v.y > love.graphics.getHeight() then --bottom of screen
|
|
table.remove(Bullets2, i)
|
|
end
|
|
end
|
|
|
|
-- Player Updates
|
|
UserPlayer1:update(dt)
|
|
UserPlayer2:update(dt)
|
|
end
|