{
"id": "281",
"prompt": "Two-player pong over host::mp: each player publishes a clamped paddle y into their OWN shared slot 0 (every peer owns a 32-slot vector all peers can read). The HOST is authoritative - only self_index() == 0 integrates the ball in its state slots, bounces it off walls and both paddles (reading each side's published paddle via get(0,0) and get(1,0)), and re-publishes ball x/y through its slots 1 and 2; the joiner just renders what the host published. auto(room) matchmaking with a waiting screen until connected().",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n host::display::clear(0x0a0a10);\n if host::display::state_get(0) == 0 {\n host::mp::auto(9);\n host::display::state_set(0, 1);\n host::display::state_set(1, w / 2);\n host::display::state_set(2, h / 2);\n host::display::state_set(3, 3);\n host::display::state_set(4, 2);\n }\n if host::mp::connected() == 0 {\n host::display::draw_string(130, 230, \"WAITING FOR THE\", 0x8899aa, 2);\n host::display::draw_string(140, 260, \"OTHER PLAYER\", 0x8899aa, 2);\n host::display::present();\n } else {\n let me: i32 = host::mp::self_index();\n let mut my_y: i32 = host::display::pointer_y() - 40;\n if my_y < 0 {\n my_y = 0;\n }\n if my_y > h - 80 {\n my_y = h - 80;\n }\n host::mp::set(0, my_y);\n if me == 0 {\n let mut bx: i32 = host::display::state_get(1);\n let mut by: i32 = host::display::state_get(2);\n let mut vx: i32 = host::display::state_get(3);\n let mut vy: i32 = host::display::state_get(4);\n bx = bx + vx;\n by = by + vy;\n if by < 0 || by > h - 10 {\n vy = 0 - vy;\n }\n let ly: i32 = host::mp::get(0, 0);\n let ry: i32 = host::mp::get(1, 0);\n if bx < 24 && by + 10 > ly && by < ly + 80 {\n vx = 0 - vx;\n }\n if bx > w - 34 && by + 10 > ry && by < ry + 80 {\n vx = 0 - vx;\n }\n if bx < 0 || bx > w {\n bx = w / 2;\n by = h / 2;\n }\n host::display::state_set(1, bx);\n host::display::state_set(2, by);\n host::display::state_set(3, vx);\n host::display::state_set(4, vy);\n host::mp::set(1, bx);\n host::mp::set(2, by);\n }\n host::display::fill_rect(14, host::mp::get(0, 0), 10, 80, 0xffcc33);\n host::display::fill_rect(w - 24, host::mp::get(1, 0), 10, 80, 0x33ff88);\n host::display::fill_rect(host::mp::get(0, 1), host::mp::get(0, 2), 10, 10, 0xffffff);\n host::display::draw_string(8, 8, \"P2P PONG SHELL\", 0x556677, 1);\n if me == 0 {\n host::display::draw_string(8, 22, \"YOU ARE HOST - LEFT\", 0xffcc33, 1);\n } else {\n host::display::draw_string(8, 22, \"YOU ARE JOINER - RIGHT\", 0x33ff88, 1);\n }\n host::display::present();\n }\n}\n",
"tags": [
"mp",
"multiplayer",
"game"
]
}