From e5ef06f61a308d65987e33bcbe448227dd472412 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Thu, 10 Aug 2017 10:16:18 -0700 Subject: [PATCH] Love:Mike: Timer now saves/loads --- love/mike/lib/keys.lua | 2 ++ love/mike/main.lua | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/love/mike/lib/keys.lua b/love/mike/lib/keys.lua index 965e8f9..162de4a 100644 --- a/love/mike/lib/keys.lua +++ b/love/mike/lib/keys.lua @@ -25,6 +25,8 @@ function love.keyreleased(key) if save_exists then --player = Tserial.unpack( love.filesystem.read( saveFile ) ) actors = GameState.load(SAVE_FILE) + -- Tell the timer to ignore time passed between the save and the load + actors.start = love.timer.getTime() - actors.end_timer end end end diff --git a/love/mike/main.lua b/love/mike/main.lua index 461c2f9..4b8af79 100644 --- a/love/mike/main.lua +++ b/love/mike/main.lua @@ -22,13 +22,13 @@ function love.load() actors.start = love.timer.getTime() - local end_timer = 0 + actors.end_timer = 0 end function love.update(dt) actors.player = check_keys(actors.player, screen, dt) actors.ball = ball_bounce(actors.player, actors.ball, dt) - end_timer = love.timer.getTime() - actors.start + actors.end_timer = love.timer.getTime() - actors.start end function love.draw() @@ -48,6 +48,6 @@ function love.draw() love.graphics.print("Score: "..actors.ball.score, screen.width -80, 10) --Timer love.graphics.setColor(125,42,19) - love.graphics.print(string.format("Time M: %.2f", end_timer/60), screen.width -85, 50) - love.graphics.print(string.format("Time S: %.2f", end_timer), screen.width -85, 30) + love.graphics.print(string.format("Time M: %.2f", actors.end_timer/60), screen.width -85, 50) + love.graphics.print(string.format("Time S: %.2f", actors.end_timer), screen.width -85, 30) end