nearly there

This commit is contained in:
Simon Kellet
2024-08-06 18:16:14 +01:00
parent 65f4ee3473
commit 86d33a7fc5
10 changed files with 172 additions and 24 deletions
+13 -3
View File
@@ -6,16 +6,16 @@ end
local function drawHealth()
love.graphics.setFont(GameFont)
local height = love.graphics.getHeight()
local width = love.graphics.getWidth()
local height = love.graphics.getHeight() / _G.Y_SCALE
local width = love.graphics.getWidth() / _G.X_SCALE
love.graphics.print("P1:" .. UserPlayer1.health, 5, 5)
love.graphics.print("P2:" .. UserPlayer2.health, width - 200, height - 95)
end
function DrawGame()
local curWidth, curHeight = love.graphics.getDimensions()
--STI
love.graphics.scale(_G.X_SCALE, _G.Y_SCALE)
GameMap:draw(0, 0, _G.X_SCALE, _G.Y_SCALE)
GameMap:resize(curWidth / _G.X_SCALE, curHeight / _G.Y_SCALE)
@@ -25,6 +25,7 @@ function DrawGame()
drawFPS()
end
-- Bullets
for _, v in ipairs(Bullets1) do
v:draw()
end
@@ -32,9 +33,18 @@ function DrawGame()
v:draw()
end
-- PowerUps
for _, v in ipairs(PowerUps) do
v:draw()
end
UserPlayer1:draw()
UserPlayer2:draw()
--Draw Health
--TODO: make this nicer looking
drawHealth()
--TODO: draw running score
--drawScore()
end
+8 -2
View File
@@ -34,9 +34,10 @@ function GameKeyPressed(key)
end
if DebugFlag and key == "1" then
UserPlayer1.speed = 50000
print("player1 speed increased!")
--UserPlayer1.speed = 50000
--print("player1 speed increased!")
end
if DebugFlag and key == "2" then
_G.CUR_LEVEL = 2
RestartGame()
@@ -47,4 +48,9 @@ function GameKeyPressed(key)
RestartGame()
love.load()
end
if key == "p" then
testP = PowerUp("speed", 300, 300, "assets/powerup.jpeg", 10)
table.insert(PowerUps, testP)
end
end
+14
View File
@@ -37,6 +37,7 @@ function UpdateGame(dt)
EnableKeyPress2 = true
end
-- Update Bullets1
for i, v in ipairs(Bullets1) do
v:update(dt)
@@ -82,6 +83,7 @@ function UpdateGame(dt)
end
end
-- Update Bullets2
for i, v in ipairs(Bullets2) do
v:update(dt)
@@ -144,6 +146,18 @@ function UpdateGame(dt)
end
end
--PowerUp timer to place
PUTimeToPlace = PUTimeToPlace - dt
--print(PUTimeToPlace)
if PUTimeToPlace <= 0 then
local w, h = love.graphics.getDimensions()
local ranx = love.math.random(30, w)
local rany = love.math.random(100, h)
local newPU = PowerUp("speed", ranx, rany, "assets/powerup.jpeg", 10)
table.insert(PowerUps, newPU)
PUTimeToPlace = _G.PU_TIMER --reset
end
UserPlayer1:handleKeys("w", "s", "a", "d", dt)
UserPlayer2:handleKeys("up", "down", "left", "right", dt)
UserPlayer1:updateCol()