{
"id": "127",
"prompt": "Bubble-pop: two bubbles rise from the bottom at hash-picked columns and speeds; tapping within a bubble pops it (squared-distance check, pop tone via host::audio::tone). A bubble that escapes off the top counts against me - three escapes and it is game over with the pop count and a tap-to-restart.",
"solution_rl": "fn hash(seed: i32) -> i32 {\n let mut h: i32 = seed * 747796405 + 2891336453;\n h = (h >> 16) ^ h;\n if h < 0 { h = 0 - h; }\n h\n}\n\nfn disc(cx: i32, cy: i32, r: i32, rgb: i32) {\n host::display::fill_rect(cx - r, cy - r, 2 * r, 2 * r, rgb);\n}\n\nfn 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, h + 20);\n host::display::state_set(2, h + 220);\n host::display::state_set(3, 1);\n host::display::state_set(4, 2);\n host::display::state_set(5, 0);\n host::display::state_set(6, 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 if host::display::state_get(7) == 1 {\n host::display::clear(0x081018);\n host::display::draw_string(110, 180, \"THEY GOT AWAY\", 0xff4040, 3);\n host::display::draw_string(140, 250, \"POPPED\", 0x808080, 2);\n host::display::draw_number(280, 244, host::display::state_get(5), 0xffffff, 3);\n host::display::draw_string(140, 320, \"TAP TO RESTART\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n host::display::clear(0x081018);\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n let mut i: i32 = 0;\n while i < 2 {\n let rnd: i32 = host::display::state_get(3 + i);\n let bx: i32 = 30 + hash(rnd * 11 + i) % (w - 60);\n let spd: i32 = 2 + hash(rnd * 5 + i) % 3;\n let mut by: i32 = host::display::state_get(1 + i);\n by = by - spd;\n let mut popped: i32 = 0;\n if tap {\n let dx: i32 = px - bx;\n let dy: i32 = py - by;\n if dx * dx + dy * dy <= 576 {\n popped = 1;\n host::audio::tone(660, 60, 0);\n host::display::state_set(5, host::display::state_get(5) + 1);\n }\n }\n if by < -20 && popped == 0 {\n let esc: i32 = host::display::state_get(6) + 1;\n host::display::state_set(6, esc);\n if esc >= 3 { host::display::state_set(7, 1); }\n popped = 1;\n }\n if popped == 1 {\n host::display::state_set(3 + i, rnd + 1);\n by = h + 20 + hash(rnd * 17 + i) % 100;\n }\n host::display::state_set(1 + i, by);\n disc(bx, by, 18, 0x2255aa);\n disc(bx, by, 14, 0x4488ff);\n disc(bx - 6, by - 6, 4, 0xbbddff);\n i = i + 1;\n }\n host::display::draw_string(8, 8, \"POPPED\", 0x808080, 2);\n host::display::draw_number(140, 8, host::display::state_get(5), 0x00ff88, 2);\n host::display::draw_string(w - 200, 8, \"ESCAPED\", 0x808080, 2);\n host::display::draw_number(w - 50, 8, host::display::state_get(6), 0xff4040, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"prng",
"audio"
]
}