From 2c200d6d116512a867e43c522f82f929381a3611 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sun, 28 Sep 2025 19:50:08 -0700 Subject: [PATCH] maybe --- app/nose/bin/breakout.ts | 22 +++++++++++----------- app/nose/bin/snake.ts | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/nose/bin/breakout.ts b/app/nose/bin/breakout.ts index d3d5e3e..74a8cf4 100644 --- a/app/nose/bin/breakout.ts +++ b/app/nose/bin/breakout.ts @@ -96,23 +96,23 @@ export function update(_delta: number, input: InputState) { if (ball.y > ROWS * CELL + 100) dead = true } -export function draw(ctx: GameContext) { - ctx.clear("#6C6FF6") +export function draw(game: GameContext) { + game.clear("#6C6FF6") const boardW = COLS * CELL const boardH = ROWS * CELL + 100 - const offsetX = (ctx.width - boardW) / 2 - const offsetY = (ctx.height - boardH) / 2 + const offsetX = (game.width - boardW) / 2 + const offsetY = (game.height - boardH) / 2 - const c = ctx.ctx + const c = game.ctx c.save() c.translate(offsetX, offsetY) // background - ctx.rectfill(0, 0, boardW, boardH, "black") + game.rectfill(0, 0, boardW, boardH, "black") // paddle - ctx.rectfill( + game.rectfill( paddleX, ROWS * CELL + 60, paddleX + PADDLE_W * CELL, @@ -121,23 +121,23 @@ export function draw(ctx: GameContext) { ) // ball - ctx.circfill(ball.x, ball.y, 6, "red") + game.circfill(ball.x, ball.y, 6, "red") // bricks for (const b of bricks) { if (b.alive) { const color = pickColor(b.x, b.y) - ctx.rectfill(b.x, b.y, (b.x + (CELL * 2)) - .5, (b.y + CELL) - .5, color) + game.rectfill(b.x, b.y, (b.x + (CELL * 2)) - .5, (b.y + CELL) - .5, color) } } // score! - ctx.text(`Score: ${score}`, 5, boardH - 18, "cyan", 12) + game.text(`Score: ${score}`, 5, boardH - 18, "cyan", 12) c.restore() // ya dead if (dead) { - ctx.centerTextX("GAME OVER", boardH + 30, "red", 24) + game.centerTextX("GAME OVER", boardH + 30, "red", 24) } } diff --git a/app/nose/bin/snake.ts b/app/nose/bin/snake.ts index eb70377..60e7fd1 100644 --- a/app/nose/bin/snake.ts +++ b/app/nose/bin/snake.ts @@ -54,29 +54,29 @@ export function update(_delta: number, input: InputState) { } } -export function draw(ctx: GameContext) { - ctx.clear() - ctx.rectfill(0, 0, ctx.width, ctx.height, "black") +export function draw(game: GameContext) { + game.clear() + game.rectfill(0, 0, game.width, game.height, "black") const boardW = WIDTH * CELL const boardH = HEIGHT * CELL // move board center → canvas center - const offsetX = (ctx.width - boardW) / 2 - const offsetY = (ctx.height - boardH) / 2 + const offsetX = (game.width - boardW) / 2 + const offsetY = (game.height - boardH) / 2 console.log("X", offsetX) console.log("Y", offsetY) - const c = ctx.ctx + const c = game.ctx c.save() c.translate(offsetX, offsetY) // board background (now local 0,0 is board top-left) - ctx.rectfill(0, 0, boardW, boardH, "green") + game.rectfill(0, 0, boardW, boardH, "green") // food - ctx.rectfill( + game.rectfill( food.x * CELL, food.y * CELL, (food.x + 1) * CELL, (food.y + 1) * CELL, "lime" @@ -84,7 +84,7 @@ export function draw(ctx: GameContext) { // snake for (const s of snake) { - ctx.rectfill( + game.rectfill( s.x * CELL, s.y * CELL, ((s.x + 1) * CELL) + .5, ((s.y + 1) * CELL) + .5, "magenta" @@ -92,11 +92,11 @@ export function draw(ctx: GameContext) { } // score! - ctx.text(`Score: ${snake.length - 1}`, 5, boardH - 18, "cyan", 12) + game.text(`Score: ${snake.length - 1}`, 5, boardH - 18, "cyan", 12) c.restore() if (dead) { - ctx.centerText("GAME OVER", "red", 50) + game.centerText("GAME OVER", "red", 50) } }