{
"id": "080",
"prompt": "Four balls of different sizes and colors bouncing around the screen at once. rustlite has no struct literals or global arrays, so lay the entities out in state slots arithmetically: ball i owns slots 8+i*4 .. 11+i*4 for x, y, vx, vy (plain pixels are fine here), seeded once behind an init latch with per-ball velocities. One while loop updates and draws all four; colors from a palette array, radius 6 + i*3.",
"solution_rl": "fn frame(t: i32) {\n let pal = [0xff5050, 0x50ff80, 0x50a0ff, 0xffd050];\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 let mut k: i32 = 0;\n while k < 4 {\n host::display::state_set(8 + k * 4, 30 + k * 40);\n host::display::state_set(9 + k * 4, 30 + k * 25);\n host::display::state_set(10 + k * 4, 2 + k);\n host::display::state_set(11 + k * 4, 3 - k % 3);\n k = k + 1;\n }\n }\n host::display::clear(0x000000);\n let mut i: i32 = 0;\n while i < 4 {\n let size: i32 = 12 + i * 6;\n let mut x: i32 = host::display::state_get(8 + i * 4);\n let mut y: i32 = host::display::state_get(9 + i * 4);\n let mut vx: i32 = host::display::state_get(10 + i * 4);\n let mut vy: i32 = host::display::state_get(11 + i * 4);\n x = x + vx;\n y = y + vy;\n if x < 0 { x = 0; vx = 0 - vx; }\n if x > w - size { x = w - size; vx = 0 - vx; }\n if y < 0 { y = 0; vy = 0 - vy; }\n if y > h - size { y = h - size; vy = 0 - vy; }\n host::display::state_set(8 + i * 4, x);\n host::display::state_set(9 + i * 4, y);\n host::display::state_set(10 + i * 4, vx);\n host::display::state_set(11 + i * 4, vy);\n host::display::fill_rect(x, y, size, size, pal[i]);\n i = i + 1;\n }\n host::display::present();\n}\n",
"tags": [
"state",
"physics",
"arrays",
"no-struct-boundary"
]
}