From 1f311679f7aae80ba75bd24a1a063f3d5e4e994c Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 27 Sep 2025 19:55:27 -0700 Subject: [PATCH] test game --- app/nose/bin/game.tsx | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/nose/bin/game.tsx diff --git a/app/nose/bin/game.tsx b/app/nose/bin/game.tsx new file mode 100644 index 0000000..61b8f4a --- /dev/null +++ b/app/nose/bin/game.tsx @@ -0,0 +1,59 @@ +/// +export const game = true + +import type { GameContext, InputState } from "@/shared/types" +import { rng } from "@/shared/utils.ts" + +const WIDTH = 960 +const HEIGHT = 540 +const SPEED = 10 +let x = rng(0, WIDTH) +let y = rng(0, HEIGHT) + +export function init() { console.log("init") } + +export function update(_delta: number, input: InputState) { + if (input.pressed.has("ArrowUp") || input.pressed.has("w")) y -= 1 * SPEED + if (input.pressed.has("ArrowDown") || input.pressed.has("s")) y += 1 * SPEED + + if (input.pressed.has("ArrowLeft") || input.pressed.has("a")) x -= 1 * SPEED + if (input.pressed.has("ArrowRight") || input.pressed.has("d")) x += 1 * SPEED +} + +export function draw(ctx: GameContext) { + ctx.clear() + + // sky background + ctx.rectfill(0, 0, ctx.width, ctx.height, "skyblue") + + // sun + ctx.circfill(800, 100, 50, "yellow") + + // grass + ctx.rectfill(0, 400, ctx.width, ctx.height, "green") + + // house body + ctx.rectfill(200, 250, 400, 400, "sienna") + + // roof (triangle-ish with lines) + ctx.line(200, 250, 300, 150, "brown") + ctx.line(400, 250, 300, 150, "brown") + ctx.line(200, 250, 400, 250, "brown") + + // door + ctx.rectfill(280, 320, 320, 400, "darkred") + + // windows + ctx.rectfill(220, 270, 260, 310, "lightblue") + ctx.rectfill(340, 270, 380, 310, "lightblue") + + // tree trunk + ctx.rectfill(500, 300, 540, 400, "saddlebrown") + // tree top (a few circles for puffiness) + ctx.circfill(520, 280, 40, "darkgreen") + ctx.circfill(480, 300, 40, "darkgreen") + ctx.circfill(560, 300, 40, "darkgreen") + + ctx.circfill(x, y, 10, "magenta") + ctx.circ(x, y, 11, "white") +}