{
"id": "040",
"prompt": "Breakout-lite: 8 bricks across the top whose alive/dead flags persist in state slots 20..27 (locals reset every frame; there is no persistent array). Ball in slots 1-4, paddle follows the pointer, a brick hit clears its slot and bounces the ball. Show bricks remaining; when all are gone, relatch the init slot so the wall rebuilds.",
"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, -2);\n let mut i: i32 = 0;\n while i < 8 {\n host::display::state_set(20 + i, 1);\n i = i + 1;\n }\n }\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() - 30;\n if px < 0 { px = 0; }\n if px > w - 60 { px = w - 60; }\n bx = bx + vx;\n by = by + vy;\n if bx < 0 { bx = 0; vx = 0 - vx; }\n if bx > w - 8 { bx = w - 8; vx = 0 - vx; }\n if by < 0 { by = 0; vy = 0 - vy; }\n if by > h - 24 && vy > 0 && bx + 8 > px && bx < px + 60 {\n by = h - 24;\n vy = 0 - vy;\n }\n if by > h {\n bx = w / 2;\n by = h / 2;\n vy = -2;\n }\n if by < 30 && by >= 14 {\n let hit: i32 = bx / bw;\n if hit >= 0 && hit < 8 && host::display::state_get(20 + hit) == 1 {\n host::display::state_set(20 + hit, 0);\n vy = 0 - vy;\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(0x000000);\n let mut alive: i32 = 0;\n let mut i: i32 = 0;\n while i < 8 {\n if host::display::state_get(20 + i) == 1 {\n alive = alive + 1;\n host::display::fill_rect(i * bw + 1, 14, bw - 2, 14, 0xff6600);\n }\n i = i + 1;\n }\n if alive == 0 { host::display::state_set(0, 0); }\n host::display::fill_rect(px, h - 16, 60, 8, 0xffffff);\n host::display::fill_rect(bx, by, 8, 8, 0x00ffcc);\n host::display::draw_number(4, 0, alive, 0x808080, 1);\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"loops"
]
}