From 360665fc3b98cba6fb40727c99d986a0067b0dd6 Mon Sep 17 00:00:00 2001 From: erose524 Date: Sun, 17 Mar 2024 17:11:06 -0400 Subject: [PATCH] added highscore (GH-15) --- luna.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/luna.lua b/luna.lua index 41d1283..14f6f87 100644 --- a/luna.lua +++ b/luna.lua @@ -28,6 +28,9 @@ deathPenalty = 200 playerKillBonus = 100 npcKillBonus = 50 scores = {0, 100, 200} +gameTime = 5 +SaveData[Level.filename()] = SaveData[Level.filename()] or {} +levelsave = SaveData[Level.filename()] enemyDeathSound = Misc.resolveSoundFile("enemydeath") playerDeathSound = Misc.resolveSoundFile("playerdeath") @@ -36,7 +39,10 @@ playerDeathSound = Misc.resolveSoundFile("playerdeath") function onStart() --Your code here Timer.hurryTime = 0 - --Timer.set(60) + Timer.set(gameTime) + if levelsave.highscore == nil then + levelsave.highscore = 0 + end initPlayers() --spawnEnemy(-199304, -200380) --Text.showMessageBox(string.format("Real Spawn Positions %d %d", player.x, player.y)) @@ -216,12 +222,23 @@ function onPlayerKill(eventToken, harmedPlayer) end function Timer.onEnd() + max_score = 0 if customHud.playerOneScore > customHud.playerTwoScore then Text.showMessageBox("Game Over. Player 1 Wins!") + max_score = customHud.playerOneScore elseif customHud.playerOneScore < customHud.playerTwoScore then Text.showMessageBox("Game Over. Player 2 Wins!") + max_score = customHud.playerTwoScore else Text.showMessageBox("Game Over. It's a tie!") + max_score = customHud.playerOneScore + end + + if max_score > levelsave.highscore then + levelsave.highscore = max_score + Text.showMessageBox(string.format("You got the highscore! %d", max_score)) + else + Text.showMessageBox(string.format("High Score %d", levelsave.highscore)) end Level.load(nil, nil, nil) end