{
"id": "133",
"prompt": "Keepie-uppie: one ball under fixed-point gravity (positions in eighths in state slots - there is no float type). Tapping on the ball knocks it up and away from the tap point, walls and ceiling bounce it back, each touch scores, and letting it hit the floor shows KEEPIES and BEST with a tap to kick off again. Render the count as a giant faint number behind the ball.",
"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) * 8);\n host::display::state_set(2, (h / 3) * 8);\n host::display::state_set(3, 8);\n host::display::state_set(4, 0);\n host::display::state_set(5, 0);\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 let score: i32 = host::display::state_get(5);\n if host::display::state_get(7) == 1 {\n host::display::clear(0x101018);\n host::display::draw_string(140, 180, \"DROPPED IT\", 0xff4040, 3);\n host::display::draw_string(130, 250, \"KEEPIES\", 0x808080, 2);\n host::display::draw_number(280, 244, score, 0xffffff, 3);\n host::display::draw_string(130, 284, \"BEST\", 0x808080, 2);\n host::display::draw_number(280, 278, host::display::state_get(6), 0x00ff88, 3);\n host::display::draw_string(140, 350, \"TAP TO KICK OFF\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let mut xf: i32 = host::display::state_get(1);\n let mut yf: 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 vy = vy + 3;\n xf = xf + vx;\n yf = yf + vy;\n let r: i32 = 22;\n if xf < r * 8 { xf = r * 8; vx = -vx * 3 / 4; }\n if xf > (w - r) * 8 { xf = (w - r) * 8; vx = -vx * 3 / 4; }\n if yf < r * 8 { yf = r * 8; vy = -vy; }\n let bx: i32 = xf / 8;\n let by: i32 = yf / 8;\n if tap {\n let dx: i32 = bx - host::display::pointer_x();\n let dy: i32 = by - host::display::pointer_y();\n if dx * dx + dy * dy <= (r + 10) * (r + 10) {\n vy = -34;\n vx = vx + dx * 4;\n if vx > 40 { vx = 40; }\n if vx < -40 { vx = -40; }\n host::display::state_set(5, score + 1);\n }\n }\n if by > h - r {\n host::display::state_set(7, 1);\n if score > host::display::state_get(6) {\n host::display::state_set(6, score);\n }\n }\n host::display::state_set(1, xf);\n host::display::state_set(2, yf);\n host::display::state_set(3, vx);\n host::display::state_set(4, vy);\n host::display::clear(0x0a1414);\n host::display::draw_number(w / 2 - 24, 60, score, 0x1e3a3a, 8);\n host::display::fill_rect(bx - r, by - r, 2 * r, 2 * r, 0xdddddd);\n host::display::fill_rect(bx - r + 6, by - r + 6, 12, 12, 0xffffff);\n host::display::fill_rect(bx - 6, by - 6, 12, 12, 0x222222);\n host::display::draw_string(8, h - 30, \"TAP THE BALL TO KEEP IT UP\", 0x557777, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"pointer",
"no-struct-boundary"
]
}