Add rotating colored obstacles to scene1 and fix Body import
This commit is contained in:
26
main.js
26
main.js
@@ -4,6 +4,7 @@
|
|||||||
Render,
|
Render,
|
||||||
Runner,
|
Runner,
|
||||||
World,
|
World,
|
||||||
|
Body,
|
||||||
Bodies,
|
Bodies,
|
||||||
Constraint,
|
Constraint,
|
||||||
Events,
|
Events,
|
||||||
@@ -50,16 +51,27 @@
|
|||||||
Bodies.rectangle(w / 2, h + 40, w, 80, {
|
Bodies.rectangle(w / 2, h + 40, w, 80, {
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
restitution: 0.8,
|
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, {
|
Bodies.rectangle(w * 0.25, h * 0.55, 160, 20, {
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
angle: -0.3,
|
angle: -0.3,
|
||||||
|
render: { fillStyle: "#22c55e", strokeStyle: "#22c55e" },
|
||||||
|
plugin: { rotSpeed: 0.1 },
|
||||||
}),
|
}),
|
||||||
Bodies.rectangle(w * 0.7, h * 0.4, 220, 24, {
|
Bodies.rectangle(w * 0.7, h * 0.4, 220, 24, {
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
angle: 0.26,
|
angle: 0.26,
|
||||||
|
render: { fillStyle: "#a855f7", strokeStyle: "#a855f7" },
|
||||||
|
plugin: { rotSpeed: -0.08 },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -192,11 +204,13 @@
|
|||||||
|
|
||||||
// Static boundaries and scene-specific obstacles.
|
// Static boundaries and scene-specific obstacles.
|
||||||
let boundaries = [];
|
let boundaries = [];
|
||||||
|
let rotators = [];
|
||||||
let currentScene = scenes[0];
|
let currentScene = scenes[0];
|
||||||
|
|
||||||
const rebuildSceneBodies = () => {
|
const rebuildSceneBodies = () => {
|
||||||
boundaries.forEach((b) => World.remove(world, b));
|
boundaries.forEach((b) => World.remove(world, b));
|
||||||
boundaries = currentScene.createBodies(width, height);
|
boundaries = currentScene.createBodies(width, height);
|
||||||
|
rotators = boundaries.filter((b) => b.plugin && b.plugin.rotSpeed);
|
||||||
World.add(world, boundaries);
|
World.add(world, boundaries);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -616,6 +630,14 @@
|
|||||||
c.stiffness = c.plugin.baseStiffness ?? c.stiffness;
|
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", () => {
|
Events.on(render, "afterRender", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user