Refine relax scene with draggable soft blobs and batch spawns
This commit is contained in:
60
main.js
60
main.js
@@ -202,51 +202,23 @@
|
|||||||
const y = spawnFromBottom
|
const y = spawnFromBottom
|
||||||
? height + config.ballRadius * 2
|
? height + config.ballRadius * 2
|
||||||
: -config.ballRadius * 2;
|
: -config.ballRadius * 2;
|
||||||
const batchMin = currentScene?.config?.spawnBatchMin ?? 1;
|
const ball = createBallBody(x, y, color);
|
||||||
const batchMax = currentScene?.config?.spawnBatchMax ?? 1;
|
ball.plugin = {
|
||||||
const batchCount =
|
color,
|
||||||
batchMin === batchMax
|
hasEntered: false,
|
||||||
? batchMin
|
entryCheckId: null,
|
||||||
: Math.max(
|
squishX: 1,
|
||||||
batchMin,
|
squishY: 1,
|
||||||
Math.floor(Math.random() * (batchMax - batchMin + 1)) + batchMin,
|
};
|
||||||
);
|
balls.push(ball);
|
||||||
for (let i = 0; i < batchCount; i += 1) {
|
World.add(world, ball);
|
||||||
const blob = createBallBodies(
|
ball.plugin.entryCheckId = setTimeout(() => {
|
||||||
Math.min(
|
ball.plugin.entryCheckId = null;
|
||||||
Math.max(
|
if (gameOver) return;
|
||||||
config.ballRadius + 10,
|
if (!ball.plugin.hasEntered && Math.abs(ball.velocity.y) < 0.2) {
|
||||||
x + (i - batchCount / 2) * config.ballRadius * 1.5,
|
triggerGameOver();
|
||||||
),
|
|
||||||
width - config.ballRadius - 10,
|
|
||||||
),
|
|
||||||
y +
|
|
||||||
i *
|
|
||||||
(spawnFromBottom
|
|
||||||
? -config.ballRadius * 0.5
|
|
||||||
: config.ballRadius * 0.5),
|
|
||||||
color,
|
|
||||||
);
|
|
||||||
if (blob.constraints.length > 0 && blob.blobId) {
|
|
||||||
blobConstraints.set(blob.blobId, blob.constraints);
|
|
||||||
}
|
}
|
||||||
blob.bodies.forEach((body) => {
|
}, 1500);
|
||||||
balls.push(body);
|
|
||||||
World.add(world, body);
|
|
||||||
if (!currentScene?.config?.noGameOver) {
|
|
||||||
body.plugin.entryCheckId = setTimeout(() => {
|
|
||||||
body.plugin.entryCheckId = null;
|
|
||||||
if (gameOver) return;
|
|
||||||
if (!body.plugin.hasEntered && Math.abs(body.velocity.y) < 0.2) {
|
|
||||||
triggerGameOver();
|
|
||||||
}
|
|
||||||
}, 1500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (blob.constraints.length > 0) {
|
|
||||||
World.add(world, blob.constraints);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const startSpawner = () => {
|
const startSpawner = () => {
|
||||||
|
|||||||
@@ -50,20 +50,20 @@
|
|||||||
render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" },
|
render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" },
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Bodies.rectangle(w / 2, -wallThickness / 2, w + wallThickness * 2, wallThickness, {
|
|
||||||
isStatic: true,
|
|
||||||
render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" },
|
|
||||||
}),
|
|
||||||
Bodies.rectangle(
|
Bodies.rectangle(
|
||||||
|
w / 2,
|
||||||
-wallThickness / 2,
|
-wallThickness / 2,
|
||||||
h / 2,
|
w + wallThickness * 2,
|
||||||
wallThickness,
|
wallThickness,
|
||||||
wallHeight,
|
|
||||||
{
|
{
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
render: { fillStyle: "#7c3aed", strokeStyle: "#7c3aed" },
|
render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" },
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Bodies.rectangle(-wallThickness / 2, h / 2, wallThickness, wallHeight, {
|
||||||
|
isStatic: true,
|
||||||
|
render: { fillStyle: "#7c3aed", strokeStyle: "#7c3aed" },
|
||||||
|
}),
|
||||||
Bodies.rectangle(
|
Bodies.rectangle(
|
||||||
w + wallThickness / 2,
|
w + wallThickness / 2,
|
||||||
h / 2,
|
h / 2,
|
||||||
|
|||||||
Reference in New Issue
Block a user