From dfb358fce2e415f8057f3774e663960f9daf3546 Mon Sep 17 00:00:00 2001 From: Daddy32 Date: Sat, 13 Dec 2025 20:42:09 +0100 Subject: [PATCH] Refine relax scene with draggable soft blobs and batch spawns --- main.js | 60 ++++++++++++------------------------------- scenes/scene-relax.js | 14 +++++----- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/main.js b/main.js index de3e0ea..16c32a0 100644 --- a/main.js +++ b/main.js @@ -202,51 +202,23 @@ const y = spawnFromBottom ? height + config.ballRadius * 2 : -config.ballRadius * 2; - const batchMin = currentScene?.config?.spawnBatchMin ?? 1; - const batchMax = currentScene?.config?.spawnBatchMax ?? 1; - const batchCount = - batchMin === batchMax - ? batchMin - : Math.max( - batchMin, - Math.floor(Math.random() * (batchMax - batchMin + 1)) + batchMin, - ); - for (let i = 0; i < batchCount; i += 1) { - const blob = createBallBodies( - Math.min( - Math.max( - config.ballRadius + 10, - x + (i - batchCount / 2) * config.ballRadius * 1.5, - ), - 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); + const ball = createBallBody(x, y, color); + ball.plugin = { + color, + hasEntered: false, + entryCheckId: null, + squishX: 1, + squishY: 1, + }; + balls.push(ball); + World.add(world, ball); + ball.plugin.entryCheckId = setTimeout(() => { + ball.plugin.entryCheckId = null; + if (gameOver) return; + if (!ball.plugin.hasEntered && Math.abs(ball.velocity.y) < 0.2) { + triggerGameOver(); } - blob.bodies.forEach((body) => { - 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); - } - } + }, 1500); }; const startSpawner = () => { diff --git a/scenes/scene-relax.js b/scenes/scene-relax.js index 01476b0..3ddd56f 100644 --- a/scenes/scene-relax.js +++ b/scenes/scene-relax.js @@ -50,20 +50,20 @@ render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" }, }, ), - Bodies.rectangle(w / 2, -wallThickness / 2, w + wallThickness * 2, wallThickness, { - isStatic: true, - render: { fillStyle: "#0ea5e9", strokeStyle: "#0ea5e9" }, - }), Bodies.rectangle( + w / 2, -wallThickness / 2, - h / 2, + w + wallThickness * 2, wallThickness, - wallHeight, { 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( w + wallThickness / 2, h / 2,