Skip to content

Commit

Permalink
added highscore (GH-15)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaroonCoffee committed Mar 17, 2024
1 parent 9d517b4 commit 360665f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion luna.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 360665f

Please sign in to comment.