use Enter to pause

This commit is contained in:
Chris Wanstrath 2025-09-29 11:18:09 -07:00
parent 6ef40f608d
commit 9a99c7329e

View File

@ -19,6 +19,7 @@ let player: Shape
let nextShape: Shape
let grid: string[][] = []
let dead = false
let paused = false
let downTick = 0
let moveTick = 0
let clearedLines: number[] = []
@ -166,6 +167,7 @@ const SHAPES: Record<string, number[][][]> = {
}
export function init() {
paused = false
score = 0
dead = false
downTick = 0
@ -182,6 +184,10 @@ export function init() {
export function update(_delta: number, input: InputState) {
if (dead) return
if (input.justPressed.has("Enter"))
paused = !paused
if (paused) return
if (input.justPressed.has(" ")) {
rotateShape()
}
@ -251,9 +257,12 @@ export function draw(game: GameContext) {
c.restore()
if (paused)
game.centerTextX("PAUSED", 200, "lime", 60)
// ya dead
if (dead)
game.centerText("GAME OVER", "red", 60)
game.centerTextX("GAME OVER", 200, "red", 60)
}
function spawn() {