Add packed stack blocks and chain timer loss
This commit is contained in:
61
src/spawn.js
61
src/spawn.js
@@ -119,10 +119,13 @@
|
||||
|
||||
const createBallBodies = (x, y, color) => {
|
||||
const scene = getCurrentScene();
|
||||
const ballPhysics = scene?.config?.ballPhysics || {};
|
||||
const commonOpts = {
|
||||
restitution: 0.72,
|
||||
friction: 0.01,
|
||||
frictionAir: 0.012,
|
||||
restitution: ballPhysics.restitution ?? 0.72,
|
||||
friction: ballPhysics.friction ?? 0.01,
|
||||
frictionAir: ballPhysics.frictionAir ?? 0.012,
|
||||
frictionStatic: ballPhysics.frictionStatic ?? 0,
|
||||
density: ballPhysics.density ?? 0.001,
|
||||
render: {
|
||||
fillStyle: color,
|
||||
strokeStyle: "#0b1222",
|
||||
@@ -320,6 +323,57 @@
|
||||
spawnCount += batchCount;
|
||||
};
|
||||
|
||||
const spawnAtPosition = ({
|
||||
x,
|
||||
y,
|
||||
color,
|
||||
markEntered = false,
|
||||
enforceSpawnLimit = true,
|
||||
} = {}) => {
|
||||
if (isGameOver()) return 0;
|
||||
const scene = getCurrentScene();
|
||||
const sceneConfig = scene?.config || {};
|
||||
const spawnLimit = sceneConfig.spawnLimit;
|
||||
if (
|
||||
enforceSpawnLimit &&
|
||||
Number.isFinite(spawnLimit) &&
|
||||
spawnCount >= spawnLimit
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
const spawnColor =
|
||||
color ??
|
||||
config.palette[Math.floor(Math.random() * config.palette.length)];
|
||||
const blob = createBallBodies(x, y, spawnColor);
|
||||
if (blob.constraints.length > 0 && blob.blobId) {
|
||||
blobConstraints.set(blob.blobId, blob.constraints);
|
||||
}
|
||||
blob.bodies.forEach((body) => {
|
||||
body.plugin = body.plugin || {};
|
||||
body.plugin.hasEntered = !!markEntered;
|
||||
if (body.plugin.entryCheckId) {
|
||||
clearTimeout(body.plugin.entryCheckId);
|
||||
body.plugin.entryCheckId = null;
|
||||
}
|
||||
balls.push(body);
|
||||
World.add(world, body);
|
||||
if (!sceneConfig.noGameOver && !markEntered) {
|
||||
body.plugin.entryCheckId = setTimeout(() => {
|
||||
body.plugin.entryCheckId = null;
|
||||
if (isGameOver()) return;
|
||||
if (!body.plugin.hasEntered && Math.abs(body.velocity.y) < 0.2) {
|
||||
triggerGameOver();
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
});
|
||||
if (blob.constraints.length > 0) {
|
||||
World.add(world, blob.constraints);
|
||||
}
|
||||
spawnCount += blob.bodies.length;
|
||||
return blob.bodies.length;
|
||||
};
|
||||
|
||||
const startSpawner = () => {
|
||||
if (isGridScene()) return;
|
||||
const scene = getCurrentScene();
|
||||
@@ -551,6 +605,7 @@
|
||||
removeBlob,
|
||||
resetSpawnState,
|
||||
spawnRowAtY,
|
||||
spawnAtPosition,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user