{
"id": "136",
"prompt": "Carnival shooting gallery: three rows of tin ducks glide across as pure functions of t (middle row reversed), a crosshair rides the pointer, and I get 20 shells for the whole game - every trigger pull spends one whether it lands or not. When the last shell goes, grade me with a match over score ranges (15..=20 eagle eye, 8..15 marksman, otherwise keep drilling) and let a tap reload.",
"solution_rl": "fn duck_x(t: i32, row: i32, k: i32, w: i32) -> i32 {\n let pos: i32 = (t * (3 + row) + k * 148 + row * 53) % (w + 80) - 40;\n if row % 2 == 1 {\n w - 40 - 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, 20);\n host::display::state_set(2, 0);\n host::display::state_set(3, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(4) == 0;\n host::display::state_set(4, down);\n let score: i32 = host::display::state_get(2);\n if host::display::state_get(3) == 1 {\n host::display::clear(0x101018);\n host::display::draw_string(120, 150, \"OUT OF SHELLS\", 0xffaa00, 3);\n host::display::draw_number(220, 200, score, 0xffffff, 5);\n match score {\n 15..=20 => {\n host::display::draw_string(170, 290, \"EAGLE EYE\", 0x00ff88, 3);\n }\n 8..15 => {\n host::display::draw_string(170, 290, \"MARKSMAN\", 0xffaa00, 3);\n }\n _ => {\n host::display::draw_string(140, 290, \"KEEP DRILLING\", 0xff4040, 3);\n }\n }\n host::display::draw_string(150, 350, \"TAP TO RELOAD\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let mut ammo: i32 = host::display::state_get(1);\n if tap && ammo > 0 {\n ammo = ammo - 1;\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n let mut hit: i32 = 0;\n let mut r: i32 = 0;\n while r < 3 {\n let ty: i32 = 90 + r * 70;\n let mut k: i32 = 0;\n while k < 4 {\n if hit == 0 {\n let tx: i32 = duck_x(t, r, k, w);\n let mut adx: i32 = px - tx;\n if adx < 0 { adx = -adx; }\n let mut ady: i32 = py - ty;\n if ady < 0 { ady = -ady; }\n if adx < 22 && ady < 18 {\n hit = 1;\n host::display::state_set(2, score + 1);\n }\n }\n k = k + 1;\n }\n r = r + 1;\n }\n if ammo == 0 { host::display::state_set(3, 1); }\n }\n host::display::state_set(1, ammo);\n host::display::clear(0x1a2410);\n let rowcol = [0xffcc44, 0xff8844, 0x66bbff];\n let mut r2: i32 = 0;\n while r2 < 3 {\n let ty2: i32 = 90 + r2 * 70;\n host::display::fill_rect(0, ty2 + 20, w, 4, 0x30401c);\n let mut k2: i32 = 0;\n while k2 < 4 {\n let tx2: i32 = duck_x(t, r2, k2, w);\n host::display::fill_rect(tx2 - 16, ty2 - 12, 32, 24, rowcol[r2]);\n host::display::fill_rect(tx2 + 8, ty2 - 8, 8, 8, 0x000000);\n k2 = k2 + 1;\n }\n r2 = r2 + 1;\n }\n let cx: i32 = host::display::pointer_x();\n let cy: i32 = host::display::pointer_y();\n host::display::draw_line(cx - 16, cy, cx + 16, cy, 0xffffff);\n host::display::draw_line(cx, cy - 16, cx, cy + 16, 0xffffff);\n host::display::draw_string(8, 8, \"AMMO\", 0x808080, 2);\n host::display::draw_number(90, 8, ammo, 0xffffff, 2);\n host::display::draw_string(w - 190, 8, \"SCORE\", 0x808080, 2);\n host::display::draw_number(w - 80, 8, score, 0x00ff88, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"functions",
"match",
"state"
]
}