Merge pull request #66 from MillaBasset/features/pausing

Added counter for amount of pauses used
This commit is contained in:
Oshisaure 2023-06-24 20:35:17 +01:00 committed by GitHub
commit 3e68af6a5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 4 deletions

View File

@ -25,6 +25,8 @@ function GameScene:new(game_mode, ruleset, inputs)
hold=false,
}
self.paused = false
self.game.pause_count = 0
self.game.pause_time = 0
DiscordRPC:update({
details = self.game.rpc_details,
state = self.game.name,
@ -33,7 +35,9 @@ function GameScene:new(game_mode, ruleset, inputs)
end
function GameScene:update()
if love.window.hasFocus() and not self.paused then
if self.paused then
self.game.pause_time = self.game.pause_time + 1
else
local inputs = {}
for input, value in pairs(self.inputs) do
inputs[input] = value
@ -50,6 +54,16 @@ end
function GameScene:render()
self.game:draw(self.paused)
if self.game.pause_time > 0 or self.game.pause_count > 0 then
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setFont(font_3x5_2)
love.graphics.printf(string.format(
"%d PAUSE%s (%s)",
self.game.pause_count,
self.game.pause_count == 1 and "" or "S",
formatTime(self.game.pause_time)
), 0, 0, 635, "right")
end
end
function GameScene:onInputPress(e)
@ -71,8 +85,12 @@ function GameScene:onInputPress(e)
scene = GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs)
elseif e.input == "pause" and not (self.game.game_over or self.game.completed) then
self.paused = not self.paused
if self.paused then pauseBGM()
else resumeBGM() end
if self.paused then
pauseBGM()
self.game.pause_count = self.game.pause_count + 1
else
resumeBGM()
end
elseif e.input == "menu_back" then
self.game:onExit()
scene = ModeSelectScene()

View File

@ -29,6 +29,8 @@ function ReplayScene:new(replay, game_mode, ruleset)
hold=false,
}
self.paused = false
self.game.pause_count = replay["pause_count"]
self.game.pause_time = replay["pause_time"]
self.replay = deepcopy(replay)
self.replay_index = 1
DiscordRPC:update({
@ -39,7 +41,7 @@ function ReplayScene:new(replay, game_mode, ruleset)
end
function ReplayScene:update()
if love.window.hasFocus() and not self.paused then
if not self.paused then
self.inputs = self.replay["inputs"][self.replay_index]["inputs"]
self.replay["inputs"][self.replay_index]["frames"] = self.replay["inputs"][self.replay_index]["frames"] - 1
if self.replay["inputs"][self.replay_index]["frames"] == 0 and self.replay_index < table.getn(self.replay["inputs"]) then
@ -64,6 +66,19 @@ function ReplayScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setFont(font_3x5_3)
love.graphics.printf("REPLAY", 0, 0, 635, "right")
love.graphics.setFont(font_3x5_2)
if self.game.pause_time and self.game.pause_count then
if self.game.pause_time > 0 or self.game.pause_count > 0 then
love.graphics.printf(string.format(
"%d PAUSE%s (%s)",
self.game.pause_count,
self.game.pause_count == 1 and "" or "S",
formatTime(self.game.pause_time)
), 0, 23, 635, "right")
end
else
love.graphics.printf("?? PAUSES (--:--.--)", 0, 23, 635, "right")
end
end
function ReplayScene:onInputPress(e)

View File

@ -136,6 +136,8 @@ function GameMode:saveReplay()
replay["gamesettings"] = config.gamesettings
replay["secret_inputs"] = self.secret_inputs
replay["timestamp"] = os.time()
replay["pause_count"] = self.pause_count
replay["pause_time"] = self.pause_time
if love.filesystem.getInfo("replays") == nil then
love.filesystem.createDirectory("replays")
end