From b0c7e8decd4318038d82dba56fb31efee0bccd98 Mon Sep 17 00:00:00 2001 From: Renan LE CARO Date: Sat, 22 Mar 2025 16:58:35 +0100 Subject: [PATCH] Ball to ball explosions cleared the top left brick --- dist/index.html | 24 ++++++++++++----------- src/gameStateMutators.ts | 41 +++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/dist/index.html b/dist/index.html index 4e1a915..a1e27c1 100644 --- a/dist/index.html +++ b/dist/index.html @@ -2489,18 +2489,20 @@ function spawnExplosion(gameState, count, x, y, color) { for(let i = 0; i < count; i++)makeParticle(gameState, x + (Math.random() - 0.5) * gameState.brickWidth / 2, y + (Math.random() - 0.5) * gameState.brickWidth / 2, (Math.random() - 0.5) * 30, (Math.random() - 0.5) * 30, color, false); } function explosionAt(gameState, index, x, y, ball) { - if (gameState.bricks[index] == "black") delete gameState.bricks[index]; - schedulGameSound(gameState, "explode", ball.x, 1); - const col = index % gameState.gridSize; - const row = Math.floor(index / gameState.gridSize); const size = 1 + gameState.perks.bigger_explosions; - // Break bricks around - for(let dx = -size; dx <= size; dx++)for(let dy = -size; dy <= size; dy++){ - const i = (0, _gameUtils.getRowColIndex)(gameState, row + dy, col + dx); - if (gameState.bricks[i] && i !== -1) { - // Study bricks resist explosions too - if (gameState.bricks[i] !== "black" && gameState.perks.sturdy_bricks > Math.random() * 5) continue; - explodeBrick(gameState, i, ball, true); + schedulGameSound(gameState, "explode", ball.x, 1); + if (index !== -1) { + if (gameState.bricks[index] == "black") delete gameState.bricks[index]; + const col = index % gameState.gridSize; + const row = Math.floor(index / gameState.gridSize); + // Break bricks around + for(let dx = -size; dx <= size; dx++)for(let dy = -size; dy <= size; dy++){ + const i = (0, _gameUtils.getRowColIndex)(gameState, row + dy, col + dx); + if (gameState.bricks[i] && i !== -1) { + // Study bricks resist explosions too + if (gameState.bricks[i] !== "black" && gameState.perks.sturdy_bricks > Math.random() * 5) continue; + explodeBrick(gameState, i, ball, true); + } } } // Blow nearby coins diff --git a/src/gameStateMutators.ts b/src/gameStateMutators.ts index 761c76d..60ff36b 100644 --- a/src/gameStateMutators.ts +++ b/src/gameStateMutators.ts @@ -251,29 +251,33 @@ export function explosionAt( y: number, ball: Ball, ) { - if (gameState.bricks[index] == "black") delete gameState.bricks[index]; + const size = 1 + gameState.perks.bigger_explosions; schedulGameSound(gameState, "explode", ball.x, 1); + if(index!==-1){ - const col = index % gameState.gridSize; - const row = Math.floor(index / gameState.gridSize); - const size = 1 + gameState.perks.bigger_explosions; - // Break bricks around - for (let dx = -size; dx <= size; dx++) { - for (let dy = -size; dy <= size; dy++) { - const i = getRowColIndex(gameState, row + dy, col + dx); - if (gameState.bricks[i] && i !== -1) { - // Study bricks resist explosions too - if ( - gameState.bricks[i] !== "black" && - gameState.perks.sturdy_bricks > Math.random() * 5 - ) - continue; - explodeBrick(gameState, i, ball, true); + if (gameState.bricks[index] == "black") delete gameState.bricks[index]; + + + const col = index % gameState.gridSize; + const row = Math.floor(index / gameState.gridSize); + // Break bricks around + for (let dx = -size; dx <= size; dx++) { + for (let dy = -size; dy <= size; dy++) { + const i = getRowColIndex(gameState, row + dy, col + dx); + if (gameState.bricks[i] && i !== -1) { + // Study bricks resist explosions too + if ( + gameState.bricks[i] !== "black" && + gameState.perks.sturdy_bricks > Math.random() * 5 + ) + continue; + explodeBrick(gameState, i, ball, true); + } } } - } + } // Blow nearby coins forEachLiveOne(gameState.coins, (c) => { const dx = c.x - x; @@ -997,8 +1001,7 @@ export function gameStateTick( clamp(b.y - y, -limit, limit) + ((Math.random() - 0.5) * limit) / 3; - let index = brickIndex(x, y); - + let index = brickIndex(x, y); explosionAt(gameState, index, x, y, a); } }),