{
"id": "113",
"prompt": "I want a proper breakout: 3 rows of 8 bricks (24 alive flags in state slots 20..43, since locals reset every frame), a paddle on the pointer, 3 lives shown as icons, a GAME OVER screen when the last life is lost and a WALL CLEARED screen when the last brick pops - both restartable with a tap. Color each brick row from an array literal.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let bw: i32 = w / 8;\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n host::display::state_set(1, w / 2);\n host::display::state_set(2, h / 2);\n host::display::state_set(3, 3);\n host::display::state_set(4, -4);\n host::display::state_set(5, 3);\n host::display::state_set(6, 0);\n let mut i: i32 = 0;\n while i < 24 {\n host::display::state_set(20 + i, 1);\n i = i + 1;\n }\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(7) == 0;\n host::display::state_set(7, down);\n let phase: i32 = host::display::state_get(6);\n if phase == 1 || phase == 2 {\n if phase == 1 {\n host::display::clear(0x180404);\n host::display::draw_string(130, 200, \"GAME OVER\", 0xff4040, 4);\n } else {\n host::display::clear(0x041804);\n host::display::draw_string(120, 200, \"WALL CLEARED\", 0x00ff88, 4);\n }\n host::display::draw_string(140, 280, \"TAP TO PLAY AGAIN\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let mut bx: i32 = host::display::state_get(1);\n let mut by: i32 = host::display::state_get(2);\n let mut vx: i32 = host::display::state_get(3);\n let mut vy: i32 = host::display::state_get(4);\n let mut px: i32 = host::display::pointer_x() - 40;\n if px < 0 { px = 0; }\n if px > w - 80 { px = w - 80; }\n bx = bx + vx;\n by = by + vy;\n if bx < 0 { bx = 0; vx = -vx; }\n if bx > w - 10 { bx = w - 10; vx = -vx; }\n if by < 0 { by = 0; vy = -vy; }\n if by > h - 30 && vy > 0 && bx + 10 > px && bx < px + 80 {\n by = h - 30;\n vy = -vy;\n }\n if by > h {\n let lives: i32 = host::display::state_get(5) - 1;\n host::display::state_set(5, lives);\n if lives <= 0 {\n host::display::state_set(6, 1);\n }\n bx = w / 2;\n by = h / 2;\n vx = 3;\n vy = -4;\n }\n if by >= 40 && by < 94 {\n let row: i32 = (by - 40) / 18;\n let colm: i32 = bx / bw;\n if row >= 0 && row < 3 && colm >= 0 && colm < 8 {\n let slot: i32 = 20 + row * 8 + colm;\n if host::display::state_get(slot) == 1 {\n host::display::state_set(slot, 0);\n vy = -vy;\n }\n }\n }\n host::display::state_set(1, bx);\n host::display::state_set(2, by);\n host::display::state_set(3, vx);\n host::display::state_set(4, vy);\n host::display::clear(0x000008);\n let cols = [0xff4444, 0xffaa00, 0x00cc66];\n let mut alive: i32 = 0;\n let mut i: i32 = 0;\n while i < 24 {\n if host::display::state_get(20 + i) == 1 {\n alive = alive + 1;\n host::display::fill_rect((i % 8) * bw + 1, 40 + (i / 8) * 18, bw - 2, 16, cols[i / 8]);\n }\n i = i + 1;\n }\n if alive == 0 { host::display::state_set(6, 2); }\n host::display::fill_rect(px, h - 20, 80, 10, 0xffffff);\n host::display::fill_rect(bx, by, 10, 10, 0x00ffcc);\n let mut lf: i32 = 0;\n while lf < host::display::state_get(5) {\n host::display::fill_rect(w - 20 - lf * 18, 8, 12, 12, 0xff4444);\n lf = lf + 1;\n }\n host::display::draw_number(8, 6, alive, 0x808080, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"loops",
"ui"
]
}