Refactor scenes into separate files
This commit is contained in:
98
scenes/scene-fastdrop.js
Normal file
98
scenes/scene-fastdrop.js
Normal file
@@ -0,0 +1,98 @@
|
||||
(() => {
|
||||
const { Bodies } = Matter;
|
||||
const scenes =
|
||||
(window.PhysilinksSceneDefs = window.PhysilinksSceneDefs || []);
|
||||
|
||||
scenes.push({
|
||||
id: "scene3",
|
||||
name: "Fast drop maze",
|
||||
config: {
|
||||
gravity: 1.25,
|
||||
spawnIntervalMs: 220,
|
||||
minChain: 3,
|
||||
palette: ["#e879f9", "#38bdf8", "#f97316", "#22c55e"],
|
||||
ballRadius: 16,
|
||||
link: {
|
||||
stiffness: 1,
|
||||
lengthScale: 0.85,
|
||||
damping: 0.15,
|
||||
lineWidth: 3,
|
||||
rope: false,
|
||||
renderType: "line",
|
||||
maxLengthMultiplier: 23.8,
|
||||
},
|
||||
},
|
||||
createBodies: (w, h) => {
|
||||
const floorHeight = Math.max(60, h * 0.1);
|
||||
const wallThickness = Math.max(28, w * 0.045);
|
||||
const wallHeight = h * 1.5;
|
||||
const pegRadius = Math.max(10, Math.min(22, Math.min(w, h) * 0.03));
|
||||
const platformHeight = Math.max(12, h * 0.02);
|
||||
const leftPlatformWidth = Math.max(120, w * 0.16);
|
||||
const rightPlatformWidth = Math.max(130, w * 0.18);
|
||||
const bodies = [
|
||||
Bodies.rectangle(
|
||||
w / 2,
|
||||
h + floorHeight / 2,
|
||||
w + wallThickness * 2,
|
||||
floorHeight,
|
||||
{
|
||||
isStatic: true,
|
||||
restitution: 0.75,
|
||||
render: { fillStyle: "#14b8a6", strokeStyle: "#14b8a6" },
|
||||
},
|
||||
),
|
||||
Bodies.rectangle(
|
||||
-wallThickness / 2,
|
||||
h / 2,
|
||||
wallThickness,
|
||||
wallHeight,
|
||||
{
|
||||
isStatic: true,
|
||||
render: { fillStyle: "#f472b6", strokeStyle: "#f472b6" },
|
||||
},
|
||||
),
|
||||
Bodies.rectangle(
|
||||
w + wallThickness / 2,
|
||||
h / 2,
|
||||
wallThickness,
|
||||
wallHeight,
|
||||
{
|
||||
isStatic: true,
|
||||
render: { fillStyle: "#f472b6", strokeStyle: "#f472b6" },
|
||||
},
|
||||
),
|
||||
];
|
||||
for (let i = 0; i < 5; i += 1) {
|
||||
const x = (w * (i + 1)) / 6;
|
||||
const y = h * 0.35 + (i % 2 === 0 ? h * 0.06 : -h * 0.05);
|
||||
bodies.push(
|
||||
Bodies.circle(x, y, pegRadius, {
|
||||
isStatic: true,
|
||||
restitution: 0.9,
|
||||
render: { fillStyle: "#facc15", strokeStyle: "#facc15" },
|
||||
}),
|
||||
);
|
||||
}
|
||||
bodies.push(
|
||||
Bodies.rectangle(w * 0.3, h * 0.55, leftPlatformWidth, platformHeight, {
|
||||
isStatic: true,
|
||||
angle: -0.3,
|
||||
render: { fillStyle: "#8b5cf6", strokeStyle: "#8b5cf6" },
|
||||
}),
|
||||
Bodies.rectangle(
|
||||
w * 0.7,
|
||||
h * 0.58,
|
||||
rightPlatformWidth,
|
||||
platformHeight * 1.05,
|
||||
{
|
||||
isStatic: true,
|
||||
angle: 0.28,
|
||||
render: { fillStyle: "#10b981", strokeStyle: "#10b981" },
|
||||
},
|
||||
),
|
||||
);
|
||||
return bodies;
|
||||
},
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user