{
"id": "121",
"prompt": "Squash practice: the ball bounces off the left wall, ceiling and floor; I guard the right edge with a paddle on pointer_y. Every 5th paddle hit speeds the ball up (capped). 3 balls per game - lose one when it slips past - then show the rally count with tap to serve again. No struct literals in rustlite, so ball x/y/vx/vy live in state slots.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\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 host::display::state_set(5, 0);\n host::display::state_set(6, 3);\n host::display::state_set(7, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(8) == 0;\n host::display::state_set(8, down);\n if host::display::state_get(7) == 1 {\n host::display::clear(0x101018);\n host::display::draw_string(120, 180, \"OUT OF BALLS\", 0xff4040, 4);\n host::display::draw_string(130, 250, \"RALLY\", 0x808080, 2);\n host::display::draw_number(250, 244, host::display::state_get(5), 0xffffff, 3);\n host::display::draw_string(140, 320, \"TAP TO SERVE\", 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 py: i32 = host::display::pointer_y() - 35;\n if py < 0 { py = 0; }\n if py > h - 70 { py = h - 70; }\n bx = bx + vx;\n by = by + vy;\n if bx < 0 { bx = 0; vx = -vx; }\n if by < 0 { by = 0; vy = -vy; }\n if by > h - 10 { by = h - 10; vy = -vy; }\n if bx > w - 26 && bx < w - 12 && vx > 0 && by + 10 > py && by < py + 70 {\n bx = w - 26;\n vx = -vx;\n let hits: i32 = host::display::state_get(5) + 1;\n host::display::state_set(5, hits);\n if hits % 5 == 0 {\n let mut mag: i32 = vx;\n if mag < 0 { mag = -mag; }\n if mag < 9 {\n if vx > 0 { vx = vx + 1; } else { vx = vx - 1; }\n }\n }\n }\n if bx > w {\n let lives: i32 = host::display::state_get(6) - 1;\n host::display::state_set(6, lives);\n if lives <= 0 { host::display::state_set(7, 1); }\n bx = w / 3;\n by = h / 3;\n vx = 3;\n vy = 2;\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 host::display::fill_rect(0, 0, 4, h, 0x404040);\n host::display::fill_rect(w - 16, py, 8, 70, 0xffffff);\n host::display::fill_rect(bx, by, 10, 10, 0x00ff88);\n host::display::draw_string(8, 10, \"RALLY\", 0x808080, 2);\n host::display::draw_number(110, 10, host::display::state_get(5), 0xffffff, 2);\n let mut lf: i32 = 0;\n while lf < host::display::state_get(6) {\n host::display::fill_rect(w - 30 - lf * 18, 10, 12, 12, 0x00ff88);\n lf = lf + 1;\n }\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"pointer",
"no-struct-boundary"
]
}