diff --git a/main.js b/main.js index bd35e3e..71b717b 100644 --- a/main.js +++ b/main.js @@ -4,6 +4,7 @@ Render, Runner, World, + Body, Bodies, Constraint, Events, @@ -50,16 +51,27 @@ Bodies.rectangle(w / 2, h + 40, w, 80, { isStatic: true, restitution: 0.8, + render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" }, + }), + Bodies.rectangle(-40, h / 2, 80, h * 2, { + isStatic: true, + render: { fillStyle: "#f97316", strokeStyle: "#f97316" }, + }), + Bodies.rectangle(w + 40, h / 2, 80, h * 2, { + isStatic: true, + render: { fillStyle: "#f97316", strokeStyle: "#f97316" }, }), - Bodies.rectangle(-40, h / 2, 80, h * 2, { isStatic: true }), - Bodies.rectangle(w + 40, h / 2, 80, h * 2, { isStatic: true }), Bodies.rectangle(w * 0.25, h * 0.55, 160, 20, { isStatic: true, angle: -0.3, + render: { fillStyle: "#22c55e", strokeStyle: "#22c55e" }, + plugin: { rotSpeed: 0.1 }, }), Bodies.rectangle(w * 0.7, h * 0.4, 220, 24, { isStatic: true, angle: 0.26, + render: { fillStyle: "#a855f7", strokeStyle: "#a855f7" }, + plugin: { rotSpeed: -0.08 }, }), ], }, @@ -192,11 +204,13 @@ // Static boundaries and scene-specific obstacles. let boundaries = []; + let rotators = []; let currentScene = scenes[0]; const rebuildSceneBodies = () => { boundaries.forEach((b) => World.remove(world, b)); boundaries = currentScene.createBodies(width, height); + rotators = boundaries.filter((b) => b.plugin && b.plugin.rotSpeed); World.add(world, boundaries); }; @@ -616,6 +630,14 @@ c.stiffness = c.plugin.baseStiffness ?? c.stiffness; } }); + // Rotate any scene rotators slowly. + const dt = (engine.timing && engine.timing.delta) || 16; + rotators.forEach((b) => { + const speed = b.plugin.rotSpeed || 0; + if (speed !== 0) { + Body.rotate(b, speed * (dt / 1000)); + } + }); }); Events.on(render, "afterRender", () => {