game: tune startscreen and gameover

This commit is contained in:
He4eT 2025-06-07 09:11:56 +02:00
commit 4a96911d25

52
game.js
View file

@ -13,13 +13,13 @@ function TIC() {
/* Stages */ /* Stages */
const gameStages = { const gameStages = {
startscreen, startScreen,
gameplay, gameScreen,
gameover, gameoverScreen,
} }
/** @type {keyof typeof gameStages} */ /** @type {keyof typeof gameStages} */
let currentStage = 'startscreen' let currentStage = 'startScreen'
/* State */ /* State */
@ -57,39 +57,47 @@ let effects = []
/* Main Menu */ /* Main Menu */
function startscreen() { function startScreen() {
if ([BTN_A, BTN_B, BTN_X, BTN_Y].map((b) => btnp(b)).some(Boolean)) { cls()
currentStage = 'gameplay'
}
cls(0)
const title = 'Morse Pit' const title = 'Morse Pit'
print(title, 12, 12, 3, false, 2) print(title, 12, 12, 3, false, 2)
const instruction = 'Press any key to start' const instruction = 'Press any key to start'
print(instruction, 12, 30, 4) print(instruction, 12, 30, 4)
if ([BTN_A, BTN_B, BTN_X, BTN_Y].map((b) => btnp(b)).some(Boolean)) {
currentStage = 'gameScreen'
}
} }
/* Gameover */ /* Gameover */
function gameover() { function gameoverScreen() {
cls(0) if (effects.length > 0) {
drawFX()
drawEnemies()
drawPlayer()
} else {
const title = 'Game Over'
print(title, 12, SCREEN_H - 24, 10, false, 2)
if ([BTN_A, BTN_B, BTN_X, BTN_Y].map((b) => btnp(b)).some(Boolean)) { if ([BTN_A, BTN_B, BTN_X, BTN_Y].map((b) => btnp(b)).some(Boolean)) {
reset() reset()
} }
}
}
drawEnemies() function gameover () {
drawPlayer() effects = [{
type: 'flash',
const title = 'Game Over' frames: '7777777777654321000000000000000000'.split(''),
print(title, 12, SCREEN_H - 24, 10, false, 2) }]
currentStage = 'gameoverScreen'
} }
/* Gameplay */ /* Gameplay */
function gameplay() { function gameScreen() {
checkColisions() checkColisions()
handleMoves() handleMoves()
@ -362,7 +370,7 @@ function checkColisions() {
]) ])
.some(([enemy, distance]) => distance < enemy.dangerZone) .some(([enemy, distance]) => distance < enemy.dangerZone)
) { ) {
currentStage = 'gameover' gameover()
} }
} }
@ -401,6 +409,10 @@ function drawLetters() {
/* Effects */ /* Effects */
const effectHandlers = { const effectHandlers = {
flash: ({ frames }) => {
const color = frames.shift()
cls(color)
},
laser: ({ from, to, frames }) => { laser: ({ from, to, frames }) => {
const color = frames.shift() const color = frames.shift()
line(from.x, from.y, to.x, to.y, color) line(from.x, from.y, to.x, to.y, color)