{
"id": "137",
"prompt": "Asteroid-belt survival: my ship steers directly with the pointer (both axes, clamped on screen) through four asteroids of hash-varied size and speed streaming right-to-left over a parallax starfield. The HUD counts seconds; any collision is fatal and shows survived plus best with a tap to launch again. Asteroid respawn positions, sizes and speeds all come from one LCG hash fn.",
"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 let mut i: i32 = 0;\n while i < 4 {\n host::display::state_set(1 + i, i + 1);\n host::display::state_set(5 + i, w + 40 + i * 130);\n i = i + 1;\n }\n host::display::state_set(9, t);\n host::display::state_set(11, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(12) == 0;\n host::display::state_set(12, down);\n let sec: i32 = (t - host::display::state_get(9)) / 60;\n if host::display::state_get(11) == 1 {\n host::display::clear(0x0a0a14);\n host::display::draw_string(130, 180, \"SHIP LOST\", 0xff4040, 4);\n host::display::draw_string(120, 250, \"SURVIVED\", 0x808080, 2);\n host::display::draw_number(290, 244, host::display::state_get(13), 0xffffff, 3);\n host::display::draw_string(120, 284, \"BEST\", 0x808080, 2);\n host::display::draw_number(290, 278, host::display::state_get(10), 0x00ff88, 3);\n host::display::draw_string(120, 350, \"TAP TO LAUNCH\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let mut px: i32 = host::display::pointer_x();\n let mut py: i32 = host::display::pointer_y();\n if px < 10 { px = 10; }\n if px > w - 30 { px = w - 30; }\n if py < 10 { py = 10; }\n if py > h - 30 { py = h - 30; }\n host::display::clear(0x0a0a14);\n let mut s: i32 = 0;\n while s < 20 {\n let sy: i32 = hash(s * 7 + 1) % h;\n let sx: i32 = (hash(s * 3 + 2) % w - (t * (1 + s % 3)) % w + w) % w;\n host::display::fill_rect(sx, sy, 2, 2, 0x303048);\n s = s + 1;\n }\n let mut i2: i32 = 0;\n while i2 < 4 {\n let rnd: i32 = host::display::state_get(1 + i2);\n let ay: i32 = 20 + hash(rnd * 31 + i2) % (h - 80);\n let asz: i32 = 20 + hash(rnd * 11 + i2) % 20;\n let spd: i32 = 3 + hash(rnd * 5 + i2) % 4;\n let mut ax: i32 = host::display::state_get(5 + i2) - spd;\n if ax < -50 {\n host::display::state_set(1 + i2, rnd + 4);\n ax = w + 20 + hash(rnd * 17 + i2) % 120;\n }\n host::display::state_set(5 + i2, ax);\n if px + 20 > ax && px < ax + asz && py + 20 > ay && py < ay + asz {\n host::display::state_set(11, 1);\n host::display::state_set(13, sec);\n if sec > host::display::state_get(10) {\n host::display::state_set(10, sec);\n }\n }\n host::display::fill_rect(ax, ay, asz, asz, 0x707078);\n host::display::fill_rect(ax + asz / 4, ay + asz / 4, asz / 4, asz / 4, 0x50505a);\n i2 = i2 + 1;\n }\n host::display::fill_triangle(px, py + 10, px + 20, py, px + 20, py + 20, 0xffffff);\n host::display::fill_rect(px + 20, py + 6, 6, 8, 0xff6600);\n host::display::draw_number(w - 90, 12, sec, 0xffffff, 3);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"prng",
"pointer"
]
}