{
"id": "285",
"prompt": "An emote wall: tapping a screen quadrant broadcasts an event value 1-4 to the peers (host::mp::send); incoming events pop a giant glyph - map the value to ! ? + or O with a match - into a 4-entry ring of state slots, each with a 90-frame fade timer. Draw dim quadrant guides with their glyphs, and render live emotes huge, dimming once their timer runs low. Drain the event queue every frame; edge-detect the taps.",
"solution_rl": "fn glyph_of(v: i32) -> i32 {\n match v {\n 1 => 33,\n 2 => 63,\n 3 => 43,\n _ => 79,\n }\n}\n\nfn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n host::display::clear(0x101018);\n if host::display::state_get(0) == 0 {\n host::mp::auto(7);\n host::display::state_set(0, 1);\n }\n if host::mp::connected() == 0 {\n host::display::draw_string(170, 240, \"CONNECTING\", 0x8899aa, 2);\n } else {\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(1);\n host::display::state_set(1, down);\n if down == 1 && prev == 0 {\n let mut v: i32 = 1;\n if host::display::pointer_x() >= w / 2 {\n v = v + 1;\n }\n if host::display::pointer_y() >= h / 2 {\n v = v + 2;\n }\n host::mp::send(v);\n }\n let mut evs: i32 = host::mp::event_count();\n while evs > 0 {\n let got: i32 = host::mp::event_next();\n let head: i32 = host::display::state_get(10);\n host::display::state_set(11 + head * 2, glyph_of(got));\n host::display::state_set(12 + head * 2, 90);\n host::display::state_set(10, (head + 1) % 4);\n evs = evs - 1;\n }\n host::display::draw_line(w / 2, 0, w / 2, h, 0x222833);\n host::display::draw_line(0, h / 2, w, h / 2, 0x222833);\n host::display::draw_char(118, 118, 33, 0x333344, 3);\n host::display::draw_char(374, 118, 63, 0x333344, 3);\n host::display::draw_char(118, 374, 43, 0x333344, 3);\n host::display::draw_char(374, 374, 79, 0x333344, 3);\n let mut i: i32 = 0;\n while i < 4 {\n let timer: i32 = host::display::state_get(12 + i * 2);\n if timer > 0 {\n let mut col: i32 = 0xffffff;\n if timer < 30 {\n col = 0x555566;\n }\n host::display::draw_char(60 + i * 110, 220, host::display::state_get(11 + i * 2), col, 8);\n host::display::state_set(12 + i * 2, timer - 1);\n }\n i = i + 1;\n }\n host::display::draw_string(8, 8, \"TAP A QUADRANT TO EMOTE\", 0x556677, 1);\n }\n host::display::present();\n}\n",
"tags": [
"mp",
"events",
"ring-buffer"
]
}