Skip to content

Commit

Permalink
load the highest score from castle.storage
Browse files Browse the repository at this point in the history
  • Loading branch information
terribleben committed Oct 15, 2019
1 parent 0d9563b commit 4d46cd1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ local Box = {

local HIGH_SCORE_STORAGE_KEY = 'highscore'

function love.load()
loadHighScore()
end

function love.draw()
love.graphics.setColor(1, 1, 0, 1)
love.graphics.rectangle('fill', Box.x, Box.y, Box.width, Box.height)

love.graphics.setColor(1, 1, 1, 1)
love.graphics.print('you clicked the box ' .. State.score .. ' times', 50, 175)

if State.highScore > 0 then
love.graphics.setColor(1, 0, 1, 1)
love.graphics.print('your best score: ' .. State.highScore .. ' clicks', 50, 195)
end
end

function love.mousepressed(x, y)
Expand All @@ -42,3 +51,12 @@ function saveHighScore(score)
castle.storage.set(HIGH_SCORE_STORAGE_KEY, score)
end)
end

function loadHighScore()
network.async(function()
local highScore = castle.storage.get(HIGH_SCORE_STORAGE_KEY)
if not (highScore == nil) then
State.highScore = highScore
end
end)
end

0 comments on commit 4d46cd1

Please sign in to comment.