game: main menu

This commit is contained in:
He4eT 2025-06-05 05:56:22 +02:00
commit da4171e50e

42
game.js
View file

@ -10,27 +10,44 @@ function TIC() {
gameStages[currentStage]() gameStages[currentStage]()
} }
/* Stages */ // Stages
let currentStage = 'gameplay'
const gameStages = { const gameStages = {
mainMenu,
gameplay, gameplay,
} }
/* State */ let currentStage = 'mainMenu'
// State
let t = 0 let t = 0
let x = 96 let x = 96
let y = 24 let y = 24
/* Main Gameplay */ // Main Menu
function mainMenu() {
if ([BTN_A, BTN_B, BTN_X, BTN_Y].map(btn).some(Boolean)) {
currentStage = 'gameplay'
}
const title = 'Morse Pit'
const instruction = 'Press any key to start'
cls(0)
print(title, 12, 12, 3, false, 2)
print(instruction, 12, 30, 4)
}
// Gameplay
function gameplay() { function gameplay() {
if (btn(0)) y-- if (btn(BTN_U)) y--
if (btn(1)) y++ if (btn(BTN_D)) y++
if (btn(2)) x-- if (btn(BTN_L)) x--
if (btn(3)) x++ if (btn(BTN_R)) x++
cls(13) cls(13)
spr(1 + (((t % 60) / 30) | 0) * 2, x, y, 14, 3, 0, 0, 2, 2) spr(1 + (((t % 60) / 30) | 0) * 2, x, y, 14, 3, 0, 0, 2, 2)
@ -38,6 +55,13 @@ function gameplay() {
t++ t++
} }
// Constants
// Buttons
const [BTN_U, BTN_D, BTN_L, BTN_R, BTN_A, BTN_B, BTN_X, BTN_Y] = [
...Array(8).keys(),
]
// <TILES> // <TILES>
// 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc // 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
// 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c // 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c