From f4675da0b04ef150d2e599c86d1ae14ba7ac59ed Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sun, 20 Dec 2020 15:08:53 -0500 Subject: [PATCH] Unlock and fix BGM, add pause button --- load/bgm.lua | 6 +++--- scene/game.lua | 10 +++++++++- scene/input_config.lua | 1 + scene/mode_select.lua | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/load/bgm.lua b/load/bgm.lua index 22843f3..950a7a7 100644 --- a/load/bgm.lua +++ b/load/bgm.lua @@ -6,7 +6,7 @@ bgm = { } local current_bgm = nil -local bgm_locked = true +local bgm_locked = false function switchBGM(sound, subsound) if bgm_locked then return end @@ -47,7 +47,7 @@ function fadeoutBGM(time) end function resetBGMFadeout(time) - current_bgm:setVolume(1) + current_bgm:setVolume(config.sfx_volume) fading_bgm = false current_bgm:play() end @@ -59,7 +59,7 @@ function processBGMFadeout(dt) fadeout_time = 0 fading_bgm = false end - current_bgm:setVolume(fadeout_time / total_fadeout_time) + current_bgm:setVolume(fadeout_time * config.sfx_volume / total_fadeout_time) end end diff --git a/scene/game.lua b/scene/game.lua index 32da8f9..685a587 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -22,6 +22,7 @@ function GameScene:new(game_mode, ruleset) rotate_180=false, hold=false, } + self.paused = false DiscordRPC:update({ details = self.game.rpc_details, state = self.game.name, @@ -29,7 +30,7 @@ function GameScene:new(game_mode, ruleset) end function GameScene:update() - if love.window.hasFocus() then + if love.window.hasFocus() and not self.paused then local inputs = {} for input, value in pairs(self.inputs) do inputs[input] = value @@ -72,6 +73,9 @@ function GameScene:render() if config.gamesettings.display_gamemode == 1 then love.graphics.printf(self.game.name .. " - " .. self.ruleset.name, 0, 460, 640, "left") end + + love.graphics.setFont(font_3x5_3) + if self.paused then love.graphics.print("PAUSED!", 80, 100) end end function GameScene:onInputPress(e) @@ -82,6 +86,10 @@ function GameScene:onInputPress(e) scene = e.input == "retry" and GameScene(self.retry_mode, self.retry_ruleset) or ModeSelectScene() elseif e.input == "retry" then scene = GameScene(self.retry_mode, self.retry_ruleset) + elseif e.input == "pause" and not (self.game.game_over or self.game.completed) then + if not self.paused then pauseBGM() + else resumeBGM() end + self.paused = not self.paused elseif e.input == "menu_back" then scene = ModeSelectScene() elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then diff --git a/scene/input_config.lua b/scene/input_config.lua index 8fcfc5d..7560f15 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -18,6 +18,7 @@ local configurable_inputs = { "rotate_180", "hold", "retry", + "pause", } local function newSetInputs() diff --git a/scene/mode_select.lua b/scene/mode_select.lua index 1ffe0f0..31e9f7b 100755 --- a/scene/mode_select.lua +++ b/scene/mode_select.lua @@ -18,6 +18,7 @@ function ModeSelectScene:new() end function ModeSelectScene:update() + switchBGM(nil) -- experimental end function ModeSelectScene:render()