diff --git a/Game/GameKeyPressed.lua b/Game/GameKeyPressed.lua index 42e0ee3..4af69a6 100644 --- a/Game/GameKeyPressed.lua +++ b/Game/GameKeyPressed.lua @@ -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 diff --git a/Menu/DrawMenu.lua b/Menu/DrawMenu.lua index f3e120f..9101ed3 100644 --- a/Menu/DrawMenu.lua +++ b/Menu/DrawMenu.lua @@ -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 \ No newline at end of file diff --git a/Menu/MenuKeyPressed.lua b/Menu/MenuKeyPressed.lua index 7905a9f..f3601f8 100644 --- a/Menu/MenuKeyPressed.lua +++ b/Menu/MenuKeyPressed.lua @@ -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!") diff --git a/Pause/DrawPause.lua b/Pause/DrawPause.lua new file mode 100644 index 0000000..ac799f0 --- /dev/null +++ b/Pause/DrawPause.lua @@ -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 \ No newline at end of file diff --git a/Pause/PauseKeyPressed.lua b/Pause/PauseKeyPressed.lua new file mode 100644 index 0000000..28dfd55 --- /dev/null +++ b/Pause/PauseKeyPressed.lua @@ -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 \ No newline at end of file diff --git a/Pause/UpdatePause.lua b/Pause/UpdatePause.lua new file mode 100644 index 0000000..2a2cc04 --- /dev/null +++ b/Pause/UpdatePause.lua @@ -0,0 +1,2 @@ +function UpdatePause(dt) +end \ No newline at end of file diff --git a/conf.lua b/conf.lua index 89f36fb..1028e84 100644 --- a/conf.lua +++ b/conf.lua @@ -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 diff --git a/constants.lua b/constants.lua index 3beeb17..d31faef 100644 --- a/constants.lua +++ b/constants.lua @@ -1,3 +1,8 @@ GAMESTATE = "MENU" + MENU_POS = 0 -MENU_MAX = 3 \ No newline at end of file +MENU_MAX = 3 --0 play, 1 ?, 2 ?, 3 quit + +PAUSED = false +PAUSE_POS = 0 +PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit \ No newline at end of file diff --git a/game.love b/game.love index 758bba3..c544369 100644 Binary files a/game.love and b/game.love differ diff --git a/libs/classic.lua b/libs/classic.lua new file mode 100644 index 0000000..cbd6f81 --- /dev/null +++ b/libs/classic.lua @@ -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 diff --git a/main.lua b/main.lua index cf099e6..f7a790f 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/music/battle.mp3 b/music/battle.mp3 new file mode 100644 index 0000000..9292c94 Binary files /dev/null and b/music/battle.mp3 differ diff --git a/music/fight.mp3 b/music/fight.mp3 new file mode 100644 index 0000000..3552771 Binary files /dev/null and b/music/fight.mp3 differ diff --git a/music/menu.mp3 b/music/menu.mp3 new file mode 100644 index 0000000..c6732c2 Binary files /dev/null and b/music/menu.mp3 differ diff --git a/music/story.mp3 b/music/story.mp3 new file mode 100644 index 0000000..98b9039 Binary files /dev/null and b/music/story.mp3 differ