done for tonight

main
Simon Kellet 4 months ago
parent cdc0f35f22
commit 9e968b9390
  1. 4
      Game/DrawGame.lua
  2. 2
      Game/GameKeyPressed.lua
  3. 11
      Game/UpdateGame.lua
  4. 9
      Menu/MenuKeyPressed.lua
  5. 1
      Pause/PauseKeyPressed.lua
  6. 3
      Win/DrawWin.lua
  7. 7
      Win/WinKeyPressed.lua
  8. 8
      constants.lua
  9. BIN
      game.love
  10. 2
      libs/restart.lua
  11. 7
      main.lua
  12. 8
      player.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()

@ -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

@ -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

@ -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

@ -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

@ -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

@ -0,0 +1,7 @@
function WinKeyPressed(key)
if key == "r" then
RestartGame()
_G.GAMESTATE = "GAME"
love.load()
end
end

@ -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

Binary file not shown.

@ -17,7 +17,7 @@ function StopAllMusic()
musicBattle:stop()
musicMenu:stop()
musicPause:stop()
musicStory:stop()
--musicStory:stop() -- Unused
end
function ClearPlayerCollision()

@ -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({

@ -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)
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)

Loading…
Cancel
Save