added pause and music

main
Simon Kellet 2 months ago
parent bcada33441
commit 19e10d6601
  1. 15
      Game/GameKeyPressed.lua
  2. 3
      Menu/DrawMenu.lua
  3. 1
      Menu/MenuKeyPressed.lua
  4. 45
      Pause/DrawPause.lua
  5. 44
      Pause/PauseKeyPressed.lua
  6. 2
      Pause/UpdatePause.lua
  7. 2
      conf.lua
  8. 7
      constants.lua
  9. BIN
      game.love
  10. 68
      libs/classic.lua
  11. 46
      main.lua
  12. BIN
      music/battle.mp3
  13. BIN
      music/fight.mp3
  14. BIN
      music/menu.mp3
  15. BIN
      music/story.mp3

@ -1,14 +1,21 @@
function GameKeyPressed(key)
if key == "escape" then
_G.GAMESTATE = "MENU"
print("STATE CHANEGD: MENU!")
musicBattle:setVolume(0)
musicPause:setVolume(0.5)
_G.GAMESTATE = "PAUSE"
print("STATE CHANEGD: PAUSED!")
_G.PAUSED = true
end
if key == "b" then
if key == "b" and not _G.PAUSED then
DebugFlag = not DebugFlag
end
if key == "r" then
--[[
if key == "r" and not _G.PAUSED then
love.load()
end
]]--
end

@ -19,7 +19,6 @@ local function button(x,y, w, h, text, selected)
-- Place text inside the rectangle
love.graphics.setFont(MenuFont)
love.graphics.print(text, textX, textY)
end
local function title()
@ -40,4 +39,6 @@ function DrawMenu()
button(100, 350, bwidth, bheight, "???", MENU_POS == 1 and true or false)
button(100, 500, bwidth, bheight, "???", MENU_POS == 2 and true or false)
button(100, 650, bwidth, bheight, "Quit", MENU_POS == 3 and true or false)
love.graphics.setColor(255,255,255) -- reset colours
end

@ -8,6 +8,7 @@ function MenuKeyPressed(key)
--Change state to GAME!
_G.GAMESTATE = "GAME"
print("STATE CHANEGD: GAME!")
musicMenu:stop()
elseif MENU_POS == 1 then
print("STATE CHANEGD: DUNNO!")

@ -0,0 +1,45 @@
local function button(x,y, w, h, text, selected)
--x,y is the top left corner of the button
local rounding = 30 -- used for rounding the buttons
if not selected then
love.graphics.setColor(love.math.colorFromBytes(41,134,204))
elseif selected then
love.graphics.setColor(love.math.colorFromBytes(244,67,54))
end
-- Draw rectangle
love.graphics.rectangle("fill", x, y, w, h, rounding, rounding)
-- Get width and height of text
local tw = MenuFont:getWidth(text)
local th = MenuFont:getHeight(text)
-- Calculate position to center the text
local textX = x + (w - tw) / 2
local textY = y + (h - th) / 2
-- Place text inside the rectangle
love.graphics.setFont(MenuFont)
love.graphics.setColor(1,1,1) -- reset colours
love.graphics.print(text, textX, textY)
end
function DrawPause()
local opacity = 0.3
local height = love.graphics.getHeight()
local width = love.graphics.getWidth()
local bwidth, bheight = 300, 140
love.graphics.setFont(GameFont)
DrawGame() --Draw a single frame of the game
love.graphics.setColor(0.1,0.1,0.1, opacity) --overlay opaque img
love.graphics.rectangle("fill", 0, 0, width, height)
love.graphics.setColor(1,1,1)
love.graphics.print("PAUSED", 100,100)
--love.graphics.print("" .. PAUSE_POS, 200,200)
button(100, 200, bwidth, bheight, "Return", PAUSE_POS == 0 and true or false)
button(100, 350, bwidth, bheight, "Menu", PAUSE_POS == 1 and true or false)
button(100, 500, bwidth, bheight, "Quit", PAUSE_POS == 2 and true or false)
love.graphics.setColor(255,255,255) -- reset colours
end

@ -0,0 +1,44 @@
function PauseKeyPressed(key)
if key == 'return' then
musicBattle:setVolume(0.5)
musicPause:setVolume(0)
-- 0 Return to game
-- 1 Quit
if PAUSE_POS == 0 then
-- unpause the game
_G.GAMESTATE = "GAME"
print("STATE CHANEGD: GAME!")
_G.PAUSED = false
musicBattle:setVolume(0.5)
musicPause:setVolume(0)
elseif PAUSE_POS == 1 then
_G.GAMESTATE = "MENU"
print("STATE CHANEGD: MENU!")
_G.PAUSED = false
musicPause:stop()
musicBattle:stop()
elseif PAUSE_POS == 2 then
love.event.quit()
end
end
if love.keyboard.isDown("up") then
if _G.PAUSE_POS == 0 then
_G.PAUSE_POS = 0
else
_G.PAUSE_POS = _G.PAUSE_POS - 1
end
end
if love.keyboard.isDown("down") then
if _G.PAUSE_POS >= _G.PAUSE_MAX then
_G.PAUSE_POS = _G.PAUSE_MAX
else
_G.PAUSE_POS = _G.PAUSE_POS + 1
end
end
end

@ -0,0 +1,2 @@
function UpdatePause(dt)
end

@ -2,5 +2,5 @@
function love.conf(t)
t.window.width = 1600
t.window.height = 960
t.window.title = "Game"
t.window.title = "Tanks-A-Lot"
end

@ -1,3 +1,8 @@
GAMESTATE = "MENU"
MENU_POS = 0
MENU_MAX = 3
MENU_MAX = 3 --0 play, 1 ?, 2 ?, 3 quit
PAUSED = false
PAUSE_POS = 0
PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit

Binary file not shown.

@ -0,0 +1,68 @@
--
-- classic
--
-- Copyright (c) 2014, rxi
--
-- This module is free software; you can redistribute it and/or modify it under
-- the terms of the MIT license. See LICENSE for details.
--
local Object = {}
Object.__index = Object
function Object:new()
end
function Object:extend()
local cls = {}
for k, v in pairs(self) do
if k:find("__") == 1 then
cls[k] = v
end
end
cls.__index = cls
cls.super = self
setmetatable(cls, self)
return cls
end
function Object:implement(...)
for _, cls in pairs({...}) do
for k, v in pairs(cls) do
if self[k] == nil and type(v) == "function" then
self[k] = v
end
end
end
end
function Object:is(T)
local mt = getmetatable(self)
while mt do
if mt == T then
return true
end
mt = getmetatable(mt)
end
return false
end
function Object:__tostring()
return "Object"
end
function Object:__call(...)
local obj = setmetatable({}, self)
obj:new(...)
return obj
end
return Object

@ -43,7 +43,7 @@ function love.run()
end
function love.load()
Object = require("classic")
Object = require("libs/classic")
require("player")
require("bullet")
@ -52,12 +52,15 @@ function love.load()
require("Game/UpdateGame")
require("Menu/UpdateMenu")
require("Pause/UpdatePause")
require("Game/DrawGame")
require("Menu/DrawMenu")
require("Pause/DrawPause")
require("Game/GameKeyPressed")
require("Menu/MenuKeyPressed")
require("Pause/PauseKeyPressed")
require("mapsloader")
@ -102,12 +105,28 @@ function love.load()
local playerSpeed = 12000
UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed)
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")
musicPause = musicBattle:clone()
musicPause:setFilter{
type = 'lowpass',
volume = 0.3,
highgain = 0.4,
}
end
function love.keypressed(key)
if _G.GAMESTATE == "MENU" then
MenuKeyPressed(key)
end
if _G.GAMESTATE == "PAUSE" then
PauseKeyPressed(key)
end
if _G.GAMESTATE == "GAME" then
GameKeyPressed(key)
end
@ -117,9 +136,31 @@ end
function love.update(dt)
if _G.GAMESTATE == "MENU" then
UpdateMenu(dt)
-- Handle music
if not musicMenu:isPlaying() then
musicMenu:setVolume(0.5)
love.audio.play(musicMenu)
end
end
if _G.GAMESTATE == "PAUSE" then
UpdatePause(dt)
-- Handle music
if not musicPause:isPlaying() then
--musicBattle:setVolume(0)
--musicPause:setVolume(0.5)
love.audio.play(musicBattle)
love.audio.play(musicPause)
end
end
if _G.GAMESTATE == "GAME" then
UpdateGame(dt)
-- Handle music
if not musicBattle:isPlaying() then
--musicBattle:setVolume(0.5)
--musicPause:setVolume(0)
love.audio.play(musicBattle)
love.audio.play(musicPause)
end
end
end
@ -127,6 +168,9 @@ function love.draw()
if _G.GAMESTATE == "MENU" then
DrawMenu()
end
if _G.GAMESTATE == "PAUSE" then
DrawPause()
end
if _G.GAMESTATE == "GAME" then
DrawGame()
if DebugFlag then

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save