Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. local highscores = {}
  2.  
  3. local ac = require("anothercurrency")
  4. local perLevelCoins = ac.registerCurrency("coinses", true)
  5.  
  6. local old = {highscore = 0, highcoins = 0}
  7. local endtimer = 0
  8.  
  9. SaveData.levelData = SaveData.levelData or {}
  10. SaveData.levelData[Level.filename()] = SaveData.levelData[Level.filename()] or {highscore = 0, highcoins = 0}
  11.  
  12. function highscores.onInitAPI()
  13.     registerEvent(highscores,"onStart")
  14.     registerEvent(highscores,"onTick")
  15.     registerEvent(highscores,"onDraw")
  16. end
  17.  
  18. function highscores.onStart()
  19.     Audio.sounds[21].muted = true
  20.     SaveData._basegame.hud.score = 0
  21.     perLevelCoins:setMoney(0)
  22.     old.highscore = SaveData.levelData[Level.filename()].highscore
  23.     old.highcoins = SaveData.levelData[Level.filename()].highcoins
  24. end
  25.  
  26. function highscores.onTick()
  27.     currentCoins = perLevelCoins:getMoney()
  28.     if Level.winState() ~= 0 then
  29.         if endtimer == 0 then
  30.             Audio.MusicChange(player.section,"Golden Stage Clear.spc")
  31.         end
  32.         endtimer = endtimer + 1
  33.         if SaveData._basegame.hud.score > old.highscore then
  34.             SaveData.levelData[Level.filename()].highscore = SaveData._basegame.hud.score
  35.         end
  36.         if currentCoins > old.highcoins then
  37.             SaveData.levelData[Level.filename()].highcoins = currentCoins
  38.         end
  39.     end
  40. end
  41.  
  42. function onDraw()
  43.     if Level.winState() ~= 0 then
  44.         Text.print("Course Clear!",270,200)
  45.         Text.print("Score:",270,240)
  46.         Text.print("Coins:",270,300)
  47.         if endtimer > 64 then
  48.             Text.print(SaveData._basegame.hud.score,390,240)
  49.             if endtimer > 128 then
  50.                 Text.print(currentCoins,390,300)
  51.                 if endtimer > 192 then
  52.                     if SaveData._basegame.hud.score > old.highscore then
  53.                         Text.print("New Highscore!",270,260)
  54.                     else
  55.                         Text.print("Highscore:" .. old.highscore,270,260)
  56.                     end
  57.                     if currentCoins > old.highcoins then
  58.                         Text.print("New Highscore!",270,320)
  59.                     else
  60.                         Text.print("Highscore:" .. old.highcoins,270,320)
  61.                     end
  62.                 end
  63.             end
  64.         end
  65.     end
  66. end
  67.  
  68. return highscores
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement