Enable concave stars and poly-decomp setup

This commit is contained in:
Daddy32
2025-12-13 20:09:33 +01:00
parent d825436f20
commit 854f19503a
4 changed files with 44 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
(() => {
const { Bodies, Body } = Matter;
const { Bodies, Body, Vertices } = Matter;
const scenes = (window.PhysilinksSceneDefs =
window.PhysilinksSceneDefs || []);
@@ -14,7 +14,7 @@
ballRadius: 22,
winCondition: {
type: "score",
target: 50000,
target: 15000,
onWin: { shoveBalls: true },
},
link: {
@@ -24,7 +24,7 @@
lineWidth: 4,
rope: false,
renderType: "spring",
maxLengthMultiplier: 4.7,
maxLengthMultiplier: 6,
},
},
createBodies: (w, h) => {
@@ -70,6 +70,29 @@
return gear;
};
const makeStar = (x, y, size, color, angle, rotSpeed) => {
const base = Vertices.fromPath(
"50 0 63 38 100 38 69 59 82 100 50 75 18 100 31 59 0 38 37 38",
);
const scale = (size || 50) / 50;
const pts = base.map((p) => ({
x: (p.x - 50) * scale,
y: (p.y - 50) * scale,
}));
return Bodies.fromVertices(
x,
y,
[pts],
{
isStatic: true,
angle,
render: { fillStyle: color, strokeStyle: color },
plugin: { rotSpeed },
},
true,
);
};
return [
Bodies.rectangle(
w / 2,
@@ -155,19 +178,16 @@
},
},
}),
// Random polygon obstacles
Bodies.polygon(w * 0.18, h * 0.28, 5, bumperRadius * 0.9, {
isStatic: true,
angle: 0.2,
render: { fillStyle: "#22c55e", strokeStyle: "#22c55e" },
plugin: { rotSpeed: -0.6 },
}),
Bodies.polygon(w * 0.86, h * 0.62, 7, bumperRadius * 0.95, {
isStatic: true,
angle: -0.25,
render: { fillStyle: "#c084fc", strokeStyle: "#c084fc" },
plugin: { rotSpeed: 0.9 },
}),
// Star obstacles
makeStar(w * 0.18, h * 0.28, bumperRadius * 1.1, "#22c55e", 0.2, -0.6),
makeStar(
w * 0.86,
h * 0.62,
bumperRadius * 1.15,
"#c084fc",
-0.25,
0.9,
),
];
},
});