{
"id": "132",
"prompt": "Duck-hunt round: a bird flaps across the screen on a triangle-wave flight path (a pure function of t - rustlite has no floats or trig), 3 shells per bird drawn as shotgun shells, crosshair on the pointer. A shot within range bags it with a tone and a fresh bird enters at a hashed height; three birds escaping off the right edge ends the hunt with a tally and a restart tap.",
"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 tri(v: i32) -> i32 {\n let m: i32 = v % 120;\n if m < 60 { m } else { 120 - m }\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, 1);\n host::display::state_set(2, -30);\n host::display::state_set(3, 3);\n host::display::state_set(4, 0);\n host::display::state_set(5, 0);\n host::display::state_set(6, 0);\n }\n let down: i32 = host::display::pointer_down();\n let tap: bool = down == 1 && host::display::state_get(7) == 0;\n host::display::state_set(7, down);\n if host::display::state_get(6) == 1 {\n host::display::clear(0x101018);\n host::display::draw_string(100, 180, \"THE FLOCK ESCAPED\", 0xff4040, 3);\n host::display::draw_string(140, 250, \"BAGGED\", 0x808080, 2);\n host::display::draw_number(290, 244, host::display::state_get(4), 0xffffff, 3);\n host::display::draw_string(130, 320, \"TAP TO HUNT AGAIN\", 0x808080, 2);\n if tap { host::display::state_set(0, 0); }\n } else {\n let round: i32 = host::display::state_get(1);\n let base: i32 = 80 + hash(round * 5) % (h - 240);\n let by: i32 = base + tri(t * 3) - 30;\n let spd: i32 = 2 + hash(round) % 3;\n let mut bx: i32 = host::display::state_get(2) + spd;\n let mut ammo: i32 = host::display::state_get(3);\n let mut next_bird: i32 = 0;\n if tap && ammo > 0 {\n ammo = ammo - 1;\n let dx: i32 = host::display::pointer_x() - bx;\n let dy: i32 = host::display::pointer_y() - by;\n if dx * dx + dy * dy <= 676 {\n host::audio::tone(440, 80, 1);\n host::display::state_set(4, host::display::state_get(4) + 1);\n next_bird = 1;\n }\n }\n if bx > w + 30 {\n let esc: i32 = host::display::state_get(5) + 1;\n host::display::state_set(5, esc);\n if esc >= 3 { host::display::state_set(6, 1); }\n next_bird = 1;\n }\n if next_bird == 1 {\n host::display::state_set(1, round + 1);\n bx = -30;\n ammo = 3;\n }\n host::display::state_set(2, bx);\n host::display::state_set(3, ammo);\n host::display::clear(0x87ceeb);\n host::display::fill_rect(0, h - 50, w, 50, 0x2d6a2d);\n host::display::fill_rect(bx - 12, by - 8, 24, 16, 0x4a3520);\n if (t / 8) % 2 == 0 {\n host::display::fill_triangle(bx - 4, by - 6, bx + 6, by - 6, bx, by - 20, 0x6a4a30);\n } else {\n host::display::fill_triangle(bx - 4, by + 6, bx + 6, by + 6, bx, by + 18, 0x6a4a30);\n }\n host::display::fill_rect(bx + 12, by - 4, 8, 6, 0xffaa00);\n let cpx: i32 = host::display::pointer_x();\n let cpy: i32 = host::display::pointer_y();\n host::display::draw_line(cpx - 14, cpy, cpx + 14, cpy, 0x202020);\n host::display::draw_line(cpx, cpy - 14, cpx, cpy + 14, 0x202020);\n let mut a: i32 = 0;\n while a < ammo {\n host::display::fill_rect(8 + a * 14, h - 30, 8, 20, 0xcc2222);\n a = a + 1;\n }\n host::display::draw_string(8, 8, \"BAGGED\", 0x204020, 2);\n host::display::draw_number(130, 8, host::display::state_get(4), 0x103010, 2);\n host::display::draw_string(w - 210, 8, \"ESCAPED\", 0x502020, 2);\n host::display::draw_number(w - 60, 8, host::display::state_get(5), 0x801010, 2);\n }\n host::display::present();\n}\n",
"tags": [
"game",
"state",
"prng",
"audio"
]
}