game: add persistent high score

This commit is contained in:
He4eT 2025-06-16 12:23:43 +02:00
commit 8dcd7ba84b

43
game.js
View file

@ -107,6 +107,7 @@ const arena = {
bottom: 105, bottom: 105,
left: 0, left: 0,
}, },
highscore: pmem(0),
wave: 0, wave: 0,
waveSeed: 0, waveSeed: 0,
} }
@ -557,13 +558,19 @@ function drawHUD() {
drawMorse(player.key.buffer, 100, 123, 15, 36) drawMorse(player.key.buffer, 100, 123, 15, 36)
print( print(
player.key.history.padStart(HISTORY_LENGTH, ' '), player.key.history.padStart(HISTORY_LENGTH),
HISTORY_X, HISTORY_X,
HISTORY_Y, HISTORY_Y,
6, 6,
true, true,
) )
print(player.score.toString().padStart(14, ' '), SCORE_X, SCORE_Y, 6, true) print(
player.score.toString().padStart(SCORE_LENGTH),
SCORE_X,
SCORE_Y,
6,
true,
)
} }
/* Start Screen */ /* Start Screen */
@ -575,8 +582,13 @@ function startScreen() {
font('DOT DASH PIT', 15, 15, 0, 7, 8, false, 1) font('DOT DASH PIT', 15, 15, 0, 7, 8, false, 1)
print('HIGH SCORE:', HISTORY_X, HISTORY_Y, 6, false) print('HIGH SCORE:', HISTORY_X, HISTORY_Y, 6, false)
// TODO highScore print(
print('0'.padStart(14, ' '), SCORE_X, SCORE_Y, 6, true) String(arena.highscore).padStart(SCORE_LENGTH),
SCORE_X,
SCORE_Y,
6,
true,
)
if (anyKeyPressed()) { if (anyKeyPressed()) {
currentScreen = 'gameScreen' currentScreen = 'gameScreen'
@ -612,8 +624,20 @@ function gameoverScreen() {
drawPlayer() drawPlayer()
if (effects.length === 0) { if (effects.length === 0) {
print('GAME OVER', HISTORY_X, HISTORY_Y, 10, false) print(
print(player.score.toString().padStart(14, ' '), SCORE_X, SCORE_Y, 6, true) player.score.toString().padStart(SCORE_LENGTH),
SCORE_X,
SCORE_Y,
6,
true,
)
print(
player.score > arena.highscore ? 'NEW HIGH SCORE!' : 'GAME OVER',
HISTORY_X,
HISTORY_Y,
player.score > arena.highscore ? 9 : 10,
false,
)
if (anyKeyPressed()) { if (anyKeyPressed()) {
reset() reset()
@ -628,6 +652,11 @@ function gameover() {
frames: '77777777777765432'.split(''), frames: '77777777777765432'.split(''),
}, },
] ]
if (player.score > arena.highscore) {
pmem(0, player.score)
}
currentScreen = 'gameoverScreen' currentScreen = 'gameoverScreen'
} }
@ -689,6 +718,7 @@ function anyKeyPressed() {
const HISTORY_LENGTH = 14 const HISTORY_LENGTH = 14
const HISTORY_X = 7 const HISTORY_X = 7
const HISTORY_Y = 118 const HISTORY_Y = 118
const SCORE_LENGTH = 14
const SCORE_X = 152 const SCORE_X = 152
const SCORE_Y = 125 const SCORE_Y = 125
const CODE_DISPLAY_W = 7 const CODE_DISPLAY_W = 7
@ -721,6 +751,7 @@ const BTN_Y = 7
* bottom: number, * bottom: number,
* left: number, * left: number,
* }, * },
* highscore: number,
* wave: number, * wave: number,
* waveSeed: number, * waveSeed: number,
* }} Arena * }} Arena