{
"id": "128",
"prompt": "Missile-command-style defense: meteors fall toward a skyline of 4 buildings (alive flags in state slots 20..23). Tapping close to a meteor destroys it and scores; a meteor that lands flattens its building. When the last building falls, show my interception count and offer a rebuild tap. Target columns, speeds and respawn delays all come from an LCG hash.",
"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 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, -20);\n host::display::state_set(2, -240);\n host::display::state_set(3, 1);\n host::display::state_set(4, 2);\n host::display::state_set(7, 0);\n host::display::state_set(8, 0);\n let mut b: i32 = 0;\n while b < 4 {\n host::display::state_set(20 + b, 1);\n b = b + 1;\n }\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(9) == 0;\n host::display::state_set(9, down);\n if host::display::state_get(8) == 1 {\n host::display::clear(0x180808);\n host::display::draw_string(120, 180, \"CITY FELL\", 0xff4040, 4);\n host::display::draw_string(120, 250, \"INTERCEPTED\", 0x808080, 2);\n host::display::draw_number(340, 244, host::display::state_get(7), 0xffffff, 3);\n host::display::draw_string(130, 320, \"TAP TO REBUILD\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n host::display::clear(0x060612);\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 colm: i32 = hash(rnd * 19 + i) % 4;\n let mx: i32 = 30 + colm * 120 + 40;\n let spd: i32 = 2 + hash(rnd * 7 + i) % 3;\n let mut my: i32 = host::display::state_get(1 + i);\n my = my + spd;\n let mut gone: i32 = 0;\n if tap {\n let dx: i32 = px - mx;\n let dy: i32 = py - my;\n if dx * dx + dy * dy <= 676 {\n gone = 1;\n host::display::state_set(7, host::display::state_get(7) + 1);\n }\n }\n if my > h - 70 && gone == 0 {\n host::display::state_set(20 + colm, 0);\n gone = 1;\n }\n if gone == 1 {\n host::display::state_set(3 + i, rnd + 1);\n my = -20 - hash(rnd * 13 + i) % 160;\n }\n host::display::state_set(1 + i, my);\n host::display::fill_rect(mx - 4, my - 26, 8, 16, 0x883311);\n host::display::fill_rect(mx - 10, my - 10, 20, 20, 0xff7722);\n host::display::fill_rect(mx - 5, my - 5, 10, 10, 0xffcc44);\n i = i + 1;\n }\n let mut alive: i32 = 0;\n let mut b2: i32 = 0;\n while b2 < 4 {\n let bx: i32 = 30 + b2 * 120;\n if host::display::state_get(20 + b2) == 1 {\n alive = alive + 1;\n host::display::fill_rect(bx, h - 70, 80, 70, 0x33415a);\n let mut wy: i32 = 0;\n while wy < 3 {\n host::display::fill_rect(bx + 12, h - 60 + wy * 20, 12, 10, 0xffe080);\n host::display::fill_rect(bx + 54, h - 60 + wy * 20, 12, 10, 0xffe080);\n wy = wy + 1;\n }\n } else {\n host::display::fill_rect(bx, h - 24, 80, 24, 0x20242c);\n }\n b2 = b2 + 1;\n }\n if alive == 0 { host::display::state_set(8, 1); }\n host::display::draw_string(8, 8, \"TAP THE METEORS\", 0x808080, 2);\n host::display::draw_number(w - 70, 8, host::display::state_get(7), 0x00ff88, 3);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"prng",
"loops"
]
}