diff --git a/Game/DrawGame.lua b/Game/DrawGame.lua index 45cb9fd..4c6bc0e 100644 --- a/Game/DrawGame.lua +++ b/Game/DrawGame.lua @@ -8,8 +8,8 @@ local function drawHealth() love.graphics.setFont(GameFont) local height = love.graphics.getHeight() local width = love.graphics.getWidth() - love.graphics.print("" .. UserPlayer1.health, 5, 5) - love.graphics.print("" .. UserPlayer2.health, width - 70, height - 95) + love.graphics.print("P1:" .. UserPlayer1.health, 5, 5) + love.graphics.print("P2:" .. UserPlayer2.health, width - 200, height - 95) end function DrawGame() diff --git a/Game/GameKeyPressed.lua b/Game/GameKeyPressed.lua index e23025c..e4d65a6 100644 --- a/Game/GameKeyPressed.lua +++ b/Game/GameKeyPressed.lua @@ -14,6 +14,8 @@ function GameKeyPressed(key) --TODO: Better restart if key == "r" and not _G.PAUSED then + RestartGame() + _G.GAMESTATE = "GAME" love.load() end end diff --git a/Game/UpdateGame.lua b/Game/UpdateGame.lua index 26b32b5..e834f98 100644 --- a/Game/UpdateGame.lua +++ b/Game/UpdateGame.lua @@ -1,15 +1,14 @@ local function checkWinState() -- Check P1's health if UserPlayer1.health <= 0 then --P1 win - _G.P1_WIN = true - _G.P2_WIN = false - UserPlayer1.health = 0 + _G.P1_WIN = false + _G.P2_WIN = true return true end + if UserPlayer2.health <= 0 then --P2 win - _G.P1_WIN = false - _G.P2_WIN = true - UserPlayer2.health = 0 + _G.P1_WIN = true + _G.P2_WIN = false return true end return false diff --git a/Menu/MenuKeyPressed.lua b/Menu/MenuKeyPressed.lua index c64853c..70b4299 100644 --- a/Menu/MenuKeyPressed.lua +++ b/Menu/MenuKeyPressed.lua @@ -33,4 +33,13 @@ function MenuKeyPressed(key) _G.MENU_POS = _G.MENU_POS + 1 end end + + if key == "r" then + musicBattle:stop() + musicMenu:stop() + musicPause:stop() + musicStory:stop() + _G.GAMESTATE = "MENU" + love.load() + end end diff --git a/Pause/PauseKeyPressed.lua b/Pause/PauseKeyPressed.lua index 3c98fe5..3d9b282 100644 --- a/Pause/PauseKeyPressed.lua +++ b/Pause/PauseKeyPressed.lua @@ -1,5 +1,6 @@ function PauseKeyPressed(key) if key == "return" then + -- quickly return to the game musicBattle:setVolume(0.5) musicPause:setVolume(0) -- 0 Return to game diff --git a/Win/DrawWin.lua b/Win/DrawWin.lua index 6d4719c..c916d6d 100644 --- a/Win/DrawWin.lua +++ b/Win/DrawWin.lua @@ -6,8 +6,7 @@ local function winner() if _G.P1_WIN then s = "P1 Win! R - Restart" - end - if _G.P2_WIN then + elseif _G.P2_WIN then s = "P2 Win! R - Restart" end diff --git a/Win/WinKeyPressed.lua b/Win/WinKeyPressed.lua new file mode 100644 index 0000000..fedabb3 --- /dev/null +++ b/Win/WinKeyPressed.lua @@ -0,0 +1,7 @@ +function WinKeyPressed(key) + if key == "r" then + RestartGame() + _G.GAMESTATE = "GAME" + love.load() + end +end diff --git a/constants.lua b/constants.lua index 0f4ec2b..8ca0035 100644 --- a/constants.lua +++ b/constants.lua @@ -15,6 +15,14 @@ PAUSED = false PAUSE_POS = 0 PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit +BULLETS_MAX = 10 -- MAX amount of bullets a player can shoot +--BULLETS_BOUCE_MAX = 7 -- MAX amount of bounces before exploding! +BULLETS_LIFETIME = 50 + -- WIN flags for P1 and P2 P1_WIN = false P2_WIN = false + +-- WIN counts! +P1_COUNT = 0 +P2_COUNT = 0 diff --git a/game.love b/game.love index 4ced93b..4ce0312 100644 Binary files a/game.love and b/game.love differ diff --git a/libs/restart.lua b/libs/restart.lua index 6fd2e1d..781ae24 100644 --- a/libs/restart.lua +++ b/libs/restart.lua @@ -17,7 +17,7 @@ function StopAllMusic() musicBattle:stop() musicMenu:stop() musicPause:stop() - musicStory:stop() + --musicStory:stop() -- Unused end function ClearPlayerCollision() diff --git a/main.lua b/main.lua index 3db4979..50488fa 100644 --- a/main.lua +++ b/main.lua @@ -94,7 +94,6 @@ function love.load() --Game consts HEALTH = 3 DELAY = 0.5 - MAX = 6 --MAX number of bullets| --Bullet lists Bullets1 = {} @@ -116,9 +115,9 @@ function love.load() UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed) -- Music streaming - musicMenu = love.audio.newSource("music/menu.mp3", "stream") - musicBattle = love.audio.newSource("music/battle.mp3", "stream") - musicStory = love.audio.newSource("music/story.mp3", "stream") + musicMenu = love.audio.newSource("music/menu.mp3", "stream") or nil + musicBattle = love.audio.newSource("music/battle.mp3", "stream") or nil + --musicStory = love.audio.newSource("music/story.mp3", "stream") or nil musicPause = musicBattle:clone() musicPause:setFilter({ diff --git a/player.lua b/player.lua index 79cd0f6..0c6d37a 100644 --- a/player.lua +++ b/player.lua @@ -35,16 +35,24 @@ function Player:new(p, x, y, health, image, speed, max) --Velocity self.vx = 0 self.vy = 0 + + -- Bullets shot + self.shot = 0 end -- Method to handle shooting function Player:shoot(bulletSpeed) - local offsetX = cos(self.rotation) * self.width * 1.5 - local offsetY = sin(self.rotation) * self.height * 1.5 - local bulletX = self.x + offsetX - local bulletY = self.y + offsetY - local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation) - return newBullet + if self.shot <= 10 then + self.shot = self.shot + 1 + local offsetX = cos(self.rotation) * self.width * 1.5 + local offsetY = sin(self.rotation) * self.height * 1.5 + local bulletX = self.x + offsetX + local bulletY = self.y + offsetY + local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation) + return newBullet + else + return nil + end end function Player:handleKeys(up, down, left, right, dt)