Unlock and fix BGM, add pause button

This commit is contained in:
Ishaan Bhardwaj 2020-12-20 15:08:53 -05:00
parent 511e9592bc
commit f4675da0b0
4 changed files with 14 additions and 4 deletions

View File

@ -6,7 +6,7 @@ bgm = {
} }
local current_bgm = nil local current_bgm = nil
local bgm_locked = true local bgm_locked = false
function switchBGM(sound, subsound) function switchBGM(sound, subsound)
if bgm_locked then return end if bgm_locked then return end
@ -47,7 +47,7 @@ function fadeoutBGM(time)
end end
function resetBGMFadeout(time) function resetBGMFadeout(time)
current_bgm:setVolume(1) current_bgm:setVolume(config.sfx_volume)
fading_bgm = false fading_bgm = false
current_bgm:play() current_bgm:play()
end end
@ -59,7 +59,7 @@ function processBGMFadeout(dt)
fadeout_time = 0 fadeout_time = 0
fading_bgm = false fading_bgm = false
end end
current_bgm:setVolume(fadeout_time / total_fadeout_time) current_bgm:setVolume(fadeout_time * config.sfx_volume / total_fadeout_time)
end end
end end

View File

@ -22,6 +22,7 @@ function GameScene:new(game_mode, ruleset)
rotate_180=false, rotate_180=false,
hold=false, hold=false,
} }
self.paused = false
DiscordRPC:update({ DiscordRPC:update({
details = self.game.rpc_details, details = self.game.rpc_details,
state = self.game.name, state = self.game.name,
@ -29,7 +30,7 @@ function GameScene:new(game_mode, ruleset)
end end
function GameScene:update() function GameScene:update()
if love.window.hasFocus() then if love.window.hasFocus() and not self.paused then
local inputs = {} local inputs = {}
for input, value in pairs(self.inputs) do for input, value in pairs(self.inputs) do
inputs[input] = value inputs[input] = value
@ -72,6 +73,9 @@ function GameScene:render()
if config.gamesettings.display_gamemode == 1 then if config.gamesettings.display_gamemode == 1 then
love.graphics.printf(self.game.name .. " - " .. self.ruleset.name, 0, 460, 640, "left") love.graphics.printf(self.game.name .. " - " .. self.ruleset.name, 0, 460, 640, "left")
end end
love.graphics.setFont(font_3x5_3)
if self.paused then love.graphics.print("PAUSED!", 80, 100) end
end end
function GameScene:onInputPress(e) 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() scene = e.input == "retry" and GameScene(self.retry_mode, self.retry_ruleset) or ModeSelectScene()
elseif e.input == "retry" then elseif e.input == "retry" then
scene = GameScene(self.retry_mode, self.retry_ruleset) 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 elseif e.input == "menu_back" then
scene = ModeSelectScene() scene = ModeSelectScene()
elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then

View File

@ -18,6 +18,7 @@ local configurable_inputs = {
"rotate_180", "rotate_180",
"hold", "hold",
"retry", "retry",
"pause",
} }
local function newSetInputs() local function newSetInputs()

View File

@ -18,6 +18,7 @@ function ModeSelectScene:new()
end end
function ModeSelectScene:update() function ModeSelectScene:update()
switchBGM(nil) -- experimental
end end
function ModeSelectScene:render() function ModeSelectScene:render()