diff --git a/app/nose/bin/tetris.ts b/app/nose/bin/tetris.ts index ada51bc..c448b13 100644 --- a/app/nose/bin/tetris.ts +++ b/app/nose/bin/tetris.ts @@ -15,6 +15,7 @@ const LOCK_DELAY = 5 type Shape = { x: number, y: number, shape: string, rotation: number } let player: Shape +let nextShape: Shape let grid: string[][] = [] let dead = false let downTick = 0 @@ -24,13 +25,13 @@ let tetrisTimer = 0 let lockTimer = 0 const COLORS: Record = { - I: "#6fc6ff", // light blue (C64 cyan) - O: "#fce94f", // yellow - T: "#d87bfb", // light purple - S: "#8ae234", // light green - Z: "#f35f5f", // red - J: "#3465a4", // blue - L: "#e9b96e", // orange + I: "cyan", + O: "yellow", + T: "magenta", + S: "lime", + Z: "red", + J: "blue", + L: "orange", } // I, O, T, L, J, S, Z @@ -161,6 +162,7 @@ export function init() { grid.length = 0 player = newShape() + nextShape = newShape() } export function update(_delta: number, input: InputState) { @@ -261,6 +263,9 @@ export function draw(game: GameContext) { } } + // "next shape" UI + drawPreview(game) + c.restore() // ya dead @@ -342,7 +347,10 @@ function lockShape() { } } - player = newShape() + player = nextShape + player.x = 3 + player.y = 0 + nextShape = newShape() } function blocked(): boolean { @@ -377,4 +385,18 @@ function drawBlock(game: GameContext, x: number, y: number, color: string) { ((y + 1) * CELL) - .5, color ) +} + +// draw next shape (top-right corner) +function drawPreview(game: GameContext) { + const previewX = COLS + 3 + const previewY = 0 + + const next = SHAPES[nextShape.shape]![0]! + for (let row = 0; row < next.length; row++) { + for (let col = 0; col < next[row]!.length; col++) { + if (!next[row]![col]) continue + drawBlock(game, previewX + col, previewY + row, COLORS[nextShape.shape]!) + } + } } \ No newline at end of file