diff --git a/Game/DrawGame.lua b/Game/DrawGame.lua index 3ac0f09..85f82ea 100644 --- a/Game/DrawGame.lua +++ b/Game/DrawGame.lua @@ -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 diff --git a/Game/GameKeyPressed.lua b/Game/GameKeyPressed.lua index 3691f34..6ff73eb 100644 --- a/Game/GameKeyPressed.lua +++ b/Game/GameKeyPressed.lua @@ -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 diff --git a/Game/UpdateGame.lua b/Game/UpdateGame.lua index 0b9f9fc..7cdb970 100644 --- a/Game/UpdateGame.lua +++ b/Game/UpdateGame.lua @@ -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() diff --git a/conf.lua b/conf.lua index fa210de..b0eb973 100644 --- a/conf.lua +++ b/conf.lua @@ -1,7 +1,11 @@ --Config file for the game function love.conf(t) - t.window.width = 1366 - t.window.height = 768 + --t.window.width = 1366 + --t.window.height = 768 + + t.window.width = 1600 + t.window.height = 960 + t.window.title = "Tanks-A-Lot" t.window.resizable = true t.version = "11.5" diff --git a/constants.lua b/constants.lua index eca2a7f..76dd5ec 100644 --- a/constants.lua +++ b/constants.lua @@ -32,13 +32,20 @@ PAUSE_POS = 0 PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit BULLETS_MAX = 10 -- MAX amount of bullets a player can shoot -BULLETS_BOUNCE_MAX = 7 -- MAX amount of bounces before exploding! -BULLETS_LIFETIME = 50 +BULLETS_BOUNCE_MAX = 10 -- MAX amount of bounces before exploding! +BULLETS_LIFETIME = 50 --TODO: impl. lifetime for a bullet! + +-- Power up timer +PU_TIMER = 10 -- WIN flags for P1 and P2 P1_WIN = false P2_WIN = false +-- Default speeds for bullets and player +DEFAULT_P_SPEED = 12000 +DEFAULT_B_SPEED = 22000 + -- WIN counts! P1_COUNT = 0 P2_COUNT = 0 diff --git a/game.love b/game.love index 4ce0312..45e2c7c 100644 Binary files a/game.love and b/game.love differ diff --git a/main.lua b/main.lua index 75141ef..2c01a0e 100644 --- a/main.lua +++ b/main.lua @@ -11,9 +11,11 @@ World:addCollisionClass("Bullet1") World:addCollisionClass("Player2") World:addCollisionClass("Bullet2") World:addCollisionClass("Wall") +World:addCollisionClass("PowerUp") require("gui") - +require("powerups/powerup") +require("powerups/speed") require("restart") require("truncate") require("player") @@ -114,17 +116,10 @@ end function love.load() -- Set a random seed love.math.setRandomSeed(love.timer.getTime()) - -- Figure out the X_SCALE and Y_SCALE local curWidth, curHeight = love.graphics.getDimensions() - - print("------") - print(love.graphics.getDimensions()) - _G.X_SCALE = truncate(curWidth / GAME_WORLD_DIM_WIDTH, 3) _G.Y_SCALE = truncate(curHeight / GAME_WORLD_DIM_HEIGHT, 3) - print("x scale:" .. _G.X_SCALE) - print("y scale:" .. _G.Y_SCALE) --Game values (reset after each load) HEALTH = 3 @@ -135,6 +130,10 @@ function love.load() Bullets1 = {} Bullets2 = {} + --PowerUp stuff + PowerUps = {} + PUTimeToPlace = _G.PU_TIMER + DebugFlag = false EnableKeyPress1 = true KeyPressTime1 = 0 @@ -144,10 +143,9 @@ function love.load() KeyPressTime2 = 0 KeyDelay2 = P2_DELAY - local playerSpeed = 12000 --TODO: two player speeds for upgrades - UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed) - UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed) + UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", 12000) + UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", 12000) --STI Map loading LoadMap(_G.CUR_LEVEL) diff --git a/player.lua b/player.lua index f88ec4d..079efe9 100644 --- a/player.lua +++ b/player.lua @@ -1,6 +1,7 @@ Player = Object:extend() local cos = math.cos local sin = math.sin --optimisation +local max = math.max --optimisation -- Constructor for the Player class function Player:new(p, x, y, health, image, speed) @@ -10,9 +11,15 @@ function Player:new(p, x, y, health, image, speed) self.y = y self.health = health self.speed = speed + self.bulletSpeed = _G.DEFAULT_B_SPEED self.width = self.image:getWidth() self.height = self.image:getHeight() + --Power up flag + self.PUName = "" + self.PUTime = 0 + self.PUOn = false + -- Collision Stuff --self.collider = World:newRectangleCollider(x, y, 50, 62) self.collider = World:newCircleCollider(x, y, 24 * X_SCALE) @@ -26,7 +33,7 @@ function Player:new(p, x, y, health, image, speed) -- Rotation Stuff self.rotation = math.rad(90) - self.rotSpeed = 2 + self.rotSpeed = 3 --self.scaleX = 1 * _G.X_SCALE --self.scaleY = 1 * _G.Y_SCALE self.scaleX = 1 @@ -86,13 +93,36 @@ function Player:updateCol() end end +function Player:getPowerUp(powerup) + self.PUName = powerup.name + self.PUTime = powerup.time +end + +function Player:powerup() + self.PUOn = true + if self.PUName == "speed" then + --print("" .. self.PUName .. " for " .. self.PUTime) + self.speed = self.speed * 2.5 + self.rotSpeed = self.rotSpeed * 1.5 + end +end + -- Update method for the Player class function Player:update(dt) - local bulletSpeed = 20000 + if self.PUOn then + self.PUTime = self.PUTime - dt + if max(0, self.PUTime) <= 0 then + -- Reset the player + self.PUName = "none" + self.PUTime = 0 + self.PUOn = false + self.speed = _G.DEFAULT_P_SPEED + end + end if EnableKeyPress1 == true and self.p == 1 then if love.keyboard.isDown("space") then - local newBullet = self:shoot(bulletSpeed) + local newBullet = self:shoot(self.bulletSpeed) table.insert(Bullets1, newBullet) KeyPressTime1 = KeyDelay1 EnableKeyPress1 = false @@ -101,7 +131,7 @@ function Player:update(dt) if EnableKeyPress2 == true and self.p == 2 then if love.keyboard.isDown("return") then - local newBullet = self:shoot(bulletSpeed) + local newBullet = self:shoot(self.bulletSpeed) table.insert(Bullets2, newBullet) KeyPressTime2 = KeyDelay2 EnableKeyPress2 = false diff --git a/powerups/powerup.lua b/powerups/powerup.lua new file mode 100644 index 0000000..d510824 --- /dev/null +++ b/powerups/powerup.lua @@ -0,0 +1,70 @@ +PowerUp = Object:extend() + +-- PowerUp is the super class for all power-ups +-- found in the game + +function PowerUp:new(name, x, y, image, time, lifetime) + self.name = name + self.x = x + self.y = y + self.image = love.graphics.newImage(image) + self.time = time + self.lifetime = lifetime + + self.width = self.image:getWidth() + self.height = self.image:getHeight() + + self.rotation = 1 + self.scaleX = 1 + self.scaleY = 1 + self.originX = self.width / 2 + self.originY = self.height / 2 + + -- Collider + self.collider = World:newRectangleCollider(x, y, 20, 20) + self.collider:setCollisionClass("PowerUp") + self.collider:setType("static") + self.collider:setPosition(self.x, self.y) +end +-- TODO: clean up colliosn on reset +-- make image draw +-- more stuff +-- see you later + +function PowerUp:apply(player) end + +function PowerUp:remove(player) end + +function PowerUp:update(dt) + --check if the power up is past its lifetime + + --spinnnnnn + self.rotation = self.rotation + 1.5 * dt + + --grown and shrink + --[[ + if self.scaleX >= 1.0 then + self.scaleX = self.scaleX - 0.2 * dt + elseif self.scaleX <= 1.8 then + self.scaleX = self.scaleX + 0.2 * dt + end + ]] + + self.x = self.collider:getX() + self.y = self.collider:getY() +end + +function PowerUp:draw() + for _, _ in ipairs(PowerUps) do + love.graphics.draw( + self.image, + self.x, + self.y, + self.rotation, + self.scaleX, + self.scaleY, + self.originX, + self.originY + ) + end +end diff --git a/restart.lua b/restart.lua index 4b5cc24..75308e6 100644 --- a/restart.lua +++ b/restart.lua @@ -8,6 +8,12 @@ function ClearWalls(walls) end end +function ClearPowerUps(powerup) + for i, v in ipairs(powerup) do + v.collider:destroy() + end +end + function StopAllMusic() -- TODO: maybe find a way -- to find all 'streaming' @@ -68,5 +74,8 @@ function RestartGame() --Clear Walls ClearWalls(Walls) + --ClearPowerUps + ClearPowerUps(PowerUps) + -- Done! end