{
"id": "122",
"prompt": "Crossing game like Frogger: four lanes of cars whose x positions are pure functions of t (alternating directions, staggered per lane - no state needed for the traffic), grass at top and bottom. Each tap hops my frog one 32px cell toward the pointer. Reaching the top bank scores a crossing and resets me; getting hit costs one of 3 lives, and at zero I get a game-over screen with crossings and tap-to-retry.",
"solution_rl": "fn car_x(t: i32, lane: i32, k: i32, w: i32) -> i32 {\n let spd: i32 = 2 + lane % 3;\n let pos: i32 = (t * spd + k * ((w + 100) / 2) + lane * 97) % (w + 100) - 50;\n if lane % 2 == 1 {\n w - 50 - pos\n } else {\n pos\n }\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, w / 2 - 16);\n host::display::state_set(2, h - 48);\n host::display::state_set(3, 3);\n host::display::state_set(4, 0);\n host::display::state_set(5, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(6) == 0;\n host::display::state_set(6, down);\n let mut fx: i32 = host::display::state_get(1);\n let mut fy: i32 = host::display::state_get(2);\n if host::display::state_get(5) == 1 {\n host::display::clear(0x101010);\n host::display::draw_string(140, 180, \"ROADKILL\", 0xff4040, 4);\n host::display::draw_string(120, 250, \"CROSSINGS\", 0x808080, 2);\n host::display::draw_number(300, 244, host::display::state_get(4), 0xffffff, 3);\n host::display::draw_string(140, 320, \"TAP TO HOP AGAIN\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n if tap {\n let dxp: i32 = host::display::pointer_x() - (fx + 16);\n let dyp: i32 = host::display::pointer_y() - (fy + 16);\n let mut ax: i32 = dxp;\n if ax < 0 { ax = -ax; }\n let mut ay: i32 = dyp;\n if ay < 0 { ay = -ay; }\n if ay >= ax {\n if dyp < 0 { fy = fy - 32; } else { fy = fy + 32; }\n } else {\n if dxp < 0 { fx = fx - 32; } else { fx = fx + 32; }\n }\n if fx < 0 { fx = 0; }\n if fx > w - 32 { fx = w - 32; }\n if fy > h - 48 { fy = h - 48; }\n if fy < 32 {\n host::display::state_set(4, host::display::state_get(4) + 1);\n fx = w / 2 - 16;\n fy = h - 48;\n }\n }\n let mut lane: i32 = 0;\n let mut hit: i32 = 0;\n while lane < 4 {\n let ly: i32 = 112 + lane * 72;\n let mut k: i32 = 0;\n while k < 2 {\n let cx: i32 = car_x(t, lane, k, w);\n if fx + 32 > cx && fx < cx + 56 && fy + 32 > ly + 10 && fy < ly + 38 {\n hit = 1;\n }\n k = k + 1;\n }\n lane = lane + 1;\n }\n if hit == 1 {\n let lives: i32 = host::display::state_get(3) - 1;\n host::display::state_set(3, lives);\n if lives <= 0 { host::display::state_set(5, 1); }\n fx = w / 2 - 16;\n fy = h - 48;\n }\n host::display::state_set(1, fx);\n host::display::state_set(2, fy);\n host::display::clear(0x202028);\n host::display::fill_rect(0, 0, w, 64, 0x0a3818);\n host::display::fill_rect(0, h - 64, w, 64, 0x0a3818);\n let mut l2: i32 = 0;\n while l2 < 4 {\n let ly2: i32 = 112 + l2 * 72;\n let mut sx: i32 = 0;\n while sx < w {\n host::display::fill_rect(sx, ly2 + 46, 24, 4, 0x404048);\n sx = sx + 48;\n }\n let mut k2: i32 = 0;\n while k2 < 2 {\n let cx2: i32 = car_x(t, l2, k2, w);\n host::display::fill_rect(cx2, ly2 + 10, 56, 28, 0xff8822);\n host::display::fill_rect(cx2 + 8, ly2 + 14, 14, 8, 0x203040);\n k2 = k2 + 1;\n }\n l2 = l2 + 1;\n }\n host::display::fill_rect(fx + 2, fy + 2, 28, 28, 0x22cc44);\n host::display::fill_rect(fx + 6, fy + 6, 6, 6, 0xffffff);\n host::display::fill_rect(fx + 20, fy + 6, 6, 6, 0xffffff);\n host::display::draw_number(8, 6, host::display::state_get(4), 0xffffff, 2);\n let mut lf: i32 = 0;\n while lf < host::display::state_get(3) {\n host::display::fill_rect(w - 26 - lf * 18, 8, 12, 12, 0x22cc44);\n lf = lf + 1;\n }\n }\n host::display::present();\n}\n",
"tags": [
"game",
"functions",
"animation",
"state"
]
}