Add chaos surge mechanic to Stack Blocks Chaos
This commit is contained in:
69
src/spawn.js
69
src/spawn.js
@@ -471,6 +471,74 @@
|
||||
spawnCount = 0;
|
||||
};
|
||||
|
||||
const spawnRowAtY = ({
|
||||
y,
|
||||
columns: columnsOverride,
|
||||
jitter = 0,
|
||||
markEntered = false,
|
||||
} = {}) => {
|
||||
const scene = getCurrentScene();
|
||||
const sceneConfig = scene?.config || {};
|
||||
const columns =
|
||||
Number.isFinite(columnsOverride) && columnsOverride > 0
|
||||
? columnsOverride
|
||||
: sceneConfig.spawnColumns;
|
||||
if (!Number.isFinite(columns) || columns <= 0) return 0;
|
||||
const { width, height } = getDimensions();
|
||||
const insets = getSpawnInsets();
|
||||
const squareArea = getSquarePlayArea();
|
||||
const usableWidth = Math.max(
|
||||
0,
|
||||
(squareArea ? squareArea.size : width) - insets.left - insets.right,
|
||||
);
|
||||
const columnWidth = usableWidth / columns;
|
||||
const minX =
|
||||
(squareArea ? squareArea.left : 0) +
|
||||
insets.left +
|
||||
config.ballRadius +
|
||||
2;
|
||||
const maxX =
|
||||
(squareArea ? squareArea.left + squareArea.size : width) -
|
||||
insets.right -
|
||||
config.ballRadius -
|
||||
2;
|
||||
const baseY =
|
||||
typeof y === "number"
|
||||
? y
|
||||
: (squareArea ? squareArea.top + squareArea.size : height) -
|
||||
config.ballRadius * 1.1;
|
||||
for (let c = 0; c < columns; c += 1) {
|
||||
const jitterX = (Math.random() - 0.5) * jitter;
|
||||
const x =
|
||||
(squareArea ? squareArea.left : 0) +
|
||||
insets.left +
|
||||
columnWidth * (c + 0.5) +
|
||||
jitterX;
|
||||
const safeX = Math.max(minX, Math.min(maxX, x));
|
||||
const color =
|
||||
config.palette[Math.floor(Math.random() * config.palette.length)];
|
||||
const blob = createBallBodies(safeX, baseY, color);
|
||||
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 (blob.constraints.length > 0) {
|
||||
World.add(world, blob.constraints);
|
||||
}
|
||||
if (blob.constraints.length > 0 && blob.blobId) {
|
||||
blobConstraints.set(blob.blobId, blob.constraints);
|
||||
}
|
||||
}
|
||||
spawnCount += columns;
|
||||
return columns;
|
||||
};
|
||||
|
||||
return {
|
||||
startSpawner,
|
||||
stopSpawner,
|
||||
@@ -482,6 +550,7 @@
|
||||
cleanupBall,
|
||||
removeBlob,
|
||||
resetSpawnState,
|
||||
spawnRowAtY,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user