Skip to content

Commit

Permalink
save the highest score with castle.storage
Browse files Browse the repository at this point in the history
  • Loading branch information
terribleben committed Oct 15, 2019
1 parent b0c9c2c commit 0d9563b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local State = {
score = 0,
highScore = 0,
}

local Box = {
Expand All @@ -9,6 +10,8 @@ local Box = {
height = 100,
}

local HIGH_SCORE_STORAGE_KEY = 'highscore'

function love.draw()
love.graphics.setColor(1, 1, 0, 1)
love.graphics.rectangle('fill', Box.x, Box.y, Box.width, Box.height)
Expand All @@ -20,6 +23,9 @@ end
function love.mousepressed(x, y)
if isInBox(x, y) then
State.score = State.score + 1
if State.score > State.highScore then
saveHighScore(State.score)
end
end
end

Expand All @@ -29,3 +35,10 @@ function isInBox(x, y)
and x <= Box.x + Box.width
and y <= Box.y + Box.height
end

function saveHighScore(score)
State.highScore = score
network.async(function()
castle.storage.set(HIGH_SCORE_STORAGE_KEY, score)
end)
end

0 comments on commit 0d9563b

Please sign in to comment.