function CheckHealth(p1, p2)
	if p1.health <= 0 then
		HasP2Won = true
		p1.health = 0
	elseif p2.health <= 0 then
		HasP1Won = true
		p2.health = 0
	end
end

function updateBG(dt)
	for _, v in ipairs(Backgrounds) do
		v:update(dt)
	end
end

function updateGame(dt)
	--update the background
	updateBG(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 _, 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
