{
"id": "087",
"prompt": "Drag-and-drop: an orange crate you can pick up ONLY if the press starts inside it (store the grab offset in state slots so it does not jump to the pointer center), and a hollow dock zone in the bottom-right corner. The zone lights up green while the crate center hovers over it during a drag; dropping it there snaps the crate into the dock and shows DOCKED. Releasing anywhere else just leaves it where it fell.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n if host::display::state_get(6) == 0 {\n host::display::state_set(6, 1);\n host::display::state_set(0, 30);\n host::display::state_set(1, 80);\n }\n let zx: i32 = w - 110;\n let zy: i32 = h - 110;\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(5);\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n let mut x: i32 = host::display::state_get(0);\n let mut y: i32 = host::display::state_get(1);\n let mut drag: i32 = host::display::state_get(2);\n if down == 1 && prev == 0 {\n if px >= x && px < x + 48 && py >= y && py < y + 48 {\n drag = 1;\n host::display::state_set(3, px - x);\n host::display::state_set(4, py - y);\n }\n }\n if drag == 1 && down == 1 {\n x = px - host::display::state_get(3);\n y = py - host::display::state_get(4);\n }\n let over: i32 = if x + 24 >= zx && x + 24 < zx + 90 && y + 24 >= zy && y + 24 < zy + 90 { 1 } else { 0 };\n if drag == 1 && down == 0 {\n drag = 0;\n if over == 1 {\n x = zx + 21;\n y = zy + 21;\n }\n }\n host::display::state_set(0, x);\n host::display::state_set(1, y);\n host::display::state_set(2, drag);\n host::display::state_set(5, down);\n host::display::clear(0x101010);\n let zc: i32 = if over == 1 { 0x00ff88 } else { 0x505050 };\n host::display::fill_rect(zx, zy, 90, 90, zc);\n host::display::fill_rect(zx + 3, zy + 3, 84, 84, 0x101010);\n if over == 1 && drag == 0 {\n host::display::draw_string(zx, zy - 16, \"DOCKED\", 0x00ff88, 1);\n }\n let cc: i32 = if drag == 1 { 0xffaa00 } else { 0xcc7700 };\n host::display::fill_rect(x, y, 48, 48, cc);\n host::display::draw_string(8, 8, \"DRAG THE CRATE TO THE DOCK\", 0x808080, 1);\n host::display::present();\n}\n",
"tags": [
"ui",
"pointer",
"state",
"drag-drop"
]
}