User prompt
arregla lo siguiente. toma a cada tipo de memes como un individuo diferente para evitar casos como el siguiente: Se combinaron 4 memes del mismo tipo pero como el movimiento conbino otros 3 no se creo el meme especial porque toma como si fueran 7 memes en vez de 4 del mismo tipo y 3 de otro
User prompt
El meme especial se activa solo cuando se combina con memes de su mismo tipo. Agrega un detector para ver si un meme de la combinación es especial. Si hay un meme especial en la combinación, se rompen todos menos la especial. Esta se activara una vez caiga
User prompt
arregla lo siguiente: el meme especial se rompe al combinarlo en vez de activar su habilidad ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
arregla lo siguiente: el meme especial se activa solo cuando se combina con memes de su mismo tipo. Agrega un detector para ver si un meme de la combinación es especial. Si hay, se rompen todos los de la combinación menos el especial, este tendra un diley y se activara
User prompt
arregla lo siguiente: el meme especial se activa solo cuando se combina con memes de su mismo tipo. Si un meme de la combinación es especial se activa la habilidad primero
User prompt
arregla lo siguiente: el meme especial se activa solo cuando se combina con memes de su mismo tipo. Si un meme de la combinación es especial se prioriza la habilidad en vez dela ruptura
User prompt
arregla lo siguiente: el meme especial no se activa al cambiar de lugar, se activa cuando se combina con memes de su mismo tipo. Se prioriza la habilidad en vez de la ruptura individual
User prompt
crea la siguiente caracteristica: si un meme se junta con un grupo de exactamente 4 este se transformara en un meme especial con un tinte naranja. Los demás memes se romperán y este permanecerá en pantalla. su habilidad sea romper toda una fila/columna, si se crea de manera horizontal rompera la columna y si se crea de una manera vertical rompera la fila. esta solo se activa si se vuelve a juntar
User prompt
agrega un modo visual de ver que meme haz seleccionado
User prompt
arregla el siguiente caso: en la parte visible se unen 3 memes pero no se rompen porque en la parte invisible hay 1 que conecta que impide la roptura a pesar que el usuario ve que se cumplen los requisitos
User prompt
haz que las ropturas se generen paralelo a cualquier otra roptura en pantalla. Esto con la finalidad de que una rotura nueva generada a la vez no tenga que esperar a que la otra finalice primero
User prompt
mejora las ropturas para que empiecen desde el meme que provoco el efecto, en forma expansiva desde el más cercano al más lejano. caso 1: se coloco la ficha horizontalmente en el lado derecho en un conjunto de 3, el primero en explotar sera el movido, el segundo el de su lado y el ultimo el más lejano haciendo un efecto domino. caso 2: Se coloco la ficha al centro de los memes, se repite el efecto domino pero los memes adyacentes se rompen simultáneamente ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
mejora la función con la siguiente especificación: SI se coloca al medio todos los adyacentes se rompera al mismo tiempo
User prompt
mejora las ropturas para que empiecen desde el meme que provoco el efecto, en forma expansiva desde el más cercano al más lejano. ej: se coloco la ficha horizontalmente en el lado derecho en un conjunto de 3, el primero en explotar sera el movido, el segundo el de su lado y el ultimo el más lejano haciendo un efecto domino ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
mejora las ropturas para que empiecen desde el meme que provoco el efecto en forma expansiva desde e más cercano al más lejano ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Evita el siguiente caso: Se juntan 3 del mismos meme 1 de ellos en el area visible y los demás en la invisible
User prompt
mejora las flag, aun se rompen memes aunque se este aplicando las caidas por gravedad
User prompt
elimina los comentarios del codigo
User prompt
mejora el codigo, optimizalo y borra comentarios
User prompt
agrega una flag para que solo se puedan romper por gravedad los grid visibles
User prompt
haz que las filas extras no se rompan por gravedad
User prompt
haz que las filas extras no se rompan por gravedad
User prompt
agrega al meme seleccionado una animación de pulso en bucle
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'easeInOutQuad')' in or related to this line: 'var pulseAnimation = tween(cell.sprite.scale, {' Line Number: 117 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'easeInOutQuad')' in or related to this line: 'var pulseAnimation = tween(cell.sprite.scale, {' Line Number: 117
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var GridCell = Container.expand(function () { var self = Container.call(this); self.init = function () { if (!self.background) { self.background = self.attachAsset('cuadricula', { anchorX: 0.5, anchorY: 0.5 }); } self.value = 0; self.sprite = null; self.row = -1; self.col = -1; return self; }; self.setValue = function (newValue) { if (self.value === newValue) { return; } self.value = newValue; if (self.sprite) { self.removeChild(self.sprite); } var spriteId = 'meme' + newValue; self.sprite = LK.getAsset(spriteId, { anchorX: 0.5, anchorY: 0.5 }); self.addChild(self.sprite); }; self.down = function (x, y, obj) { handleCellTap(self); }; self.init(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xF4FFFF }); /**** * Game Code ****/ var cellPool = []; function getGridCell() { if (cellPool.length > 0) { return cellPool.pop().init(); } return new GridCell(); } function recycleGridCell(cell) { if (cell) { cellPool.push(cell); } } var selectedCell = null; var isAnimating = false; window.gravityInProgress = false; window.fillInProgress = false; window.destructionInProgress = false; window.pendingDestructions = []; function handleCellTap(tappedCell) { if (isAnimating || window.gravityInProgress || window.fillInProgress || window.destructionInProgress) { return; } if (!tappedCell || !gridCells[tappedCell.row] || gridCells[tappedCell.row][tappedCell.col] !== tappedCell) { return; } if (selectedCell === null) { selectedCell = tappedCell; return; } if (!selectedCell || !gridCells[selectedCell.row] || gridCells[selectedCell.row][selectedCell.col] !== selectedCell) { selectedCell = tappedCell; return; } var cell1 = selectedCell; var cell2 = tappedCell; if (cell1 === cell2) { selectedCell = null; return; } var isAdjacent = Math.abs(cell1.row - cell2.row) === 1 && cell1.col === cell2.col || Math.abs(cell1.col - cell2.col) === 1 && cell1.row === cell2.row; if (!isAdjacent) { selectedCell = tappedCell; return; } isAnimating = true; var pos1_x = cell1.x; var pos1_y = cell1.y; var pos2_x = cell2.x; var pos2_y = cell2.y; var row1 = cell1.row; var col1 = cell1.col; var row2 = cell2.row; var col2 = cell2.col; gridCells[row1][col1] = cell2; gridCells[row2][col2] = cell1; cell1.row = row2; cell1.col = col2; cell2.row = row1; cell2.col = col1; tween(cell1, { x: pos2_x, y: pos2_y }, { duration: 300 }); tween(cell2, { x: pos1_x, y: pos1_y }, { duration: 300 }); selectedCell = null; LK.setTimeout(function () { checkForAndDestroyMatches(cell1, cell2); if (!window.destructionInProgress && !window.gravityInProgress && !window.fillInProgress) { isAnimating = false; } }, 350); } function getMatches() { var matches = []; function findDirectionalMatches(isHorizontal) { var primary, secondary; var primaryMax = isHorizontal ? gridSize + extraRows : gridSize; var secondaryMax = isHorizontal ? gridSize : gridSize + extraRows; for (primary = isHorizontal ? extraRows : 0; primary < primaryMax; primary++) { if (!gridCells[primary]) { continue; } for (secondary = 0; secondary < secondaryMax;) { if (secondary > secondaryMax - 3) { secondary++; continue; } var cell1 = isHorizontal ? gridCells[primary] ? gridCells[primary][secondary] : null : gridCells[secondary] ? gridCells[secondary][primary] : null; if (!cell1 || !cell1.value) { secondary++; continue; } var currentMatchValue = cell1.value; var currentMatchCells = [cell1]; for (var k = secondary + 1; k < secondaryMax; k++) { var nextCell = isHorizontal ? gridCells[primary] ? gridCells[primary][k] : null : gridCells[k] ? gridCells[k][primary] : null; if (nextCell && nextCell.value === currentMatchValue) { currentMatchCells.push(nextCell); } else { break; } } if (currentMatchCells.length >= 3) { var validCells = currentMatchCells.filter(function (cell) { return cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell; }); if (validCells.length >= 3) { var visibleCells = validCells.filter(function (cell) { return cell.row >= extraRows; }); var invisibleCells = validCells.filter(function (cell) { return cell.row < extraRows; }); if (visibleCells.length === 0 || invisibleCells.length === 0) { matches.push(validCells); } } } secondary += currentMatchCells.length > 0 ? currentMatchCells.length : 1; } } } findDirectionalMatches(true); findDirectionalMatches(false); return matches; } function destroyCells(cellsToDestroy) { isAnimating = true; if (window.destructionInProgress || window.gravityInProgress || window.fillInProgress) { if (!window.pendingDestructions) { window.pendingDestructions = []; } window.pendingDestructions.push(cellsToDestroy); return; } window.destructionInProgress = true; // Check if match crosses visible/invisible boundary var visibleCells = cellsToDestroy.filter(function (cell) { return cell.row >= extraRows; }); var invisibleCells = cellsToDestroy.filter(function (cell) { return cell.row < extraRows; }); // If mixed visibility and only one cell is visible, don't destroy any if (visibleCells.length > 0 && invisibleCells.length > 0 && (visibleCells.length === 1 || invisibleCells.length === 1)) { window.destructionInProgress = false; isAnimating = false; return; } var visibleCellsToDestroy = cellsToDestroy.filter(function (cell) { return cell.row >= extraRows && cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell; }); // Find the center cell (the one that triggered the match) var centerCell = null; // If we have the cells from a swap, use one of those as the center if (arguments.length > 1 && arguments[1]) { centerCell = arguments[1]; } else if (cellsToDestroy.length > 0) { // Otherwise use the middle cell of the match centerCell = cellsToDestroy[Math.floor(cellsToDestroy.length / 2)]; } // Sort cells by distance from center cell for ripple effect if (centerCell && visibleCellsToDestroy.length > 0) { visibleCellsToDestroy.sort(function (a, b) { var distA = Math.abs(a.row - centerCell.row) + Math.abs(a.col - centerCell.col); var distB = Math.abs(b.row - centerCell.row) + Math.abs(b.col - centerCell.col); return distA - distB; }); } var delay = 0; var delayIncrement = 100; var totalDestructionTime = visibleCellsToDestroy.length * delayIncrement; visibleCellsToDestroy.forEach(function (cell) { LK.setTimeout(function () { if (cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell) { LK.getSound('Explosion').play(); LK.effects.flashObject(cell, 0xFFFFFF, 200); gridContainer.removeChild(cell); cell.destroy(); gridCells[cell.row][cell.col] = null; } }, delay); delay += delayIncrement; }); LK.setTimeout(function () { window.destructionInProgress = false; if (window.pendingDestructions && window.pendingDestructions.length > 0) { var nextDestructions = window.pendingDestructions.shift(); LK.setTimeout(function () { destroyCells(nextDestructions); }, 50); return; } if (!window.gravityInProgress && !window.fillInProgress) { applyGravity(); } }, totalDestructionTime + 50); } function applyGravity() { isAnimating = true; var cellsToFall = []; if (window.gravityInProgress || window.destructionInProgress) { return; } window.gravityInProgress = true; for (var col = 0; col < gridSize; col++) { for (var row = gridSize + extraRows - 1; row >= extraRows; row--) { if (!gridCells[row][col]) { var sourceRow = row - 1; while (sourceRow >= 0 && !gridCells[sourceRow][col]) { sourceRow--; } if (sourceRow >= 0) { var cellToMove = gridCells[sourceRow][col]; if (cellToMove) { cellsToFall.push({ cell: cellToMove, fromRow: sourceRow, toRow: row, col: col }); gridCells[row][col] = cellToMove; gridCells[sourceRow][col] = null; cellToMove.row = row; if (sourceRow < extraRows) { gridContainer.addChild(cellToMove); } } } } } } var longestDelay = 0; var baseDelay = 30; var constantDuration = 400; cellsToFall.sort(function (a, b) { if (a.col !== b.col) { return a.col - b.col; } return b.toRow - a.toRow; }); cellsToFall.forEach(function (fallInfo, index) { var delay = index * baseDelay; var newPos = getCellPosition(fallInfo.toRow, fallInfo.col); var totalTime = delay + constantDuration; if (totalTime > longestDelay) { longestDelay = totalTime; } LK.setTimeout(function () { if (fallInfo.cell && gridCells[fallInfo.cell.row] && gridCells[fallInfo.cell.row][fallInfo.cell.col] === fallInfo.cell) { tween(fallInfo.cell, { y: newPos.y }, { duration: constantDuration, easing: tween.linear }); } }, delay); }); LK.setTimeout(function () { window.gravityInProgress = false; if (!window.destructionInProgress) { fillEmptySpacesWithNewMemes(); } }, longestDelay + 50); } function fillEmptySpacesWithNewMemes() { if (window.fillInProgress || window.gravityInProgress || window.destructionInProgress) { return; } window.fillInProgress = true; var anyNewMemeAdded = false; var newCellsToAdd = []; for (var col = 0; col < gridSize; col++) { for (var row = 0; row < gridSize + extraRows; row++) { if (!gridCells[row][col]) { anyNewMemeAdded = true; var newCell = getGridCell(); var pos = getCellPosition(row, col); newCell.x = pos.x; newCell.y = pos.y - 400; var randomValue = Math.floor(Math.random() * 5) + 1; newCell.setValue(randomValue); newCell.row = row; newCell.col = col; gridCells[row][col] = newCell; newCellsToAdd.push({ cell: newCell, destY: pos.y, row: row, col: col }); if (row >= extraRows) { gridContainer.addChild(newCell); } } } } var longestDelay = 0; var baseDelay = 30; var constantDuration = 400; newCellsToAdd.sort(function (a, b) { if (a.col !== b.col) { return a.col - b.col; } return b.row - a.row; }); newCellsToAdd.forEach(function (cellData, index) { var delay = index * baseDelay; var totalTime = delay + constantDuration; if (totalTime > longestDelay) { longestDelay = totalTime; } LK.setTimeout(function () { if (cellData.cell && gridCells[cellData.row] && gridCells[cellData.row][cellData.col] === cellData.cell) { tween(cellData.cell, { y: cellData.destY }, { duration: constantDuration, easing: tween.linear }); } }, delay); }); if (anyNewMemeAdded) { LK.setTimeout(function () { window.fillInProgress = false; if (window.destructionInProgress || window.gravityInProgress) { isAnimating = false; return; } var visibleMatchGroups = getMatches().filter(function (group) { // Check if the match has cells in both visible and invisible areas var visibleCells = group.filter(function (cell) { return cell.row >= extraRows; }); var invisibleCells = group.filter(function (cell) { return cell.row < extraRows; }); // Don't count groups with both visible and invisible cells where either group is just 1 cell if (visibleCells.length > 0 && invisibleCells.length > 0 && (visibleCells.length === 1 || invisibleCells.length === 1)) { return false; } return group.some(function (cell) { return cell.row >= extraRows; }); }); var newMatches = visibleMatchGroups; if (newMatches.length > 0) { var newCellsToDestroy = []; var newCellTracker = {}; newMatches.forEach(function (group) { group.forEach(function (cell) { var cellKey = cell.row + "_" + cell.col; if (!newCellTracker[cellKey] && cell.row >= extraRows && cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell) { newCellsToDestroy.push(cell); newCellTracker[cellKey] = true; } }); }); if (newCellsToDestroy.length) { // Find a central cell for the auto-match after gravity var centerCell = null; if (newMatches.length > 0 && newMatches[0].length > 0) { // Pick the center of the first match group var matchGroup = newMatches[0]; centerCell = matchGroup[Math.floor(matchGroup.length / 2)]; } destroyCells(newCellsToDestroy, centerCell); } else { isAnimating = false; } } else { isAnimating = false; } }, longestDelay + 50); } else { window.fillInProgress = false; isAnimating = false; } } function checkForAndDestroyMatches(swappedCellA, swappedCellB) { if (window.destructionInProgress || window.gravityInProgress || window.fillInProgress) { return; } var allMatchGroupsOnBoard = getMatches(); if (!allMatchGroupsOnBoard.length) { return; } var relevantMatchGroups = allMatchGroupsOnBoard.filter(function (group) { // Check if the match has cells in both visible and invisible areas var visibleCells = group.filter(function (cell) { return cell.row >= extraRows; }); var invisibleCells = group.filter(function (cell) { return cell.row < extraRows; }); // Don't count groups with both visible and invisible cells where either group is just 1 cell if (visibleCells.length > 0 && invisibleCells.length > 0 && (visibleCells.length === 1 || invisibleCells.length === 1)) { return false; } return group.some(function (cellInGroup) { return (cellInGroup === swappedCellA || cellInGroup === swappedCellB) && cellInGroup.row >= extraRows; }); }); if (!relevantMatchGroups.length) { return; } var uniqueCellTracker = {}; var cellsToDestroy = []; relevantMatchGroups.forEach(function (group) { group.forEach(function (cell) { var cellKey = cell.row + "_" + cell.col; if (!uniqueCellTracker[cellKey] && cell.row >= extraRows && cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell) { cellsToDestroy.push(cell); uniqueCellTracker[cellKey] = true; } }); }); if (cellsToDestroy.length) { // Pass the swapped cell that created the match as the center for the ripple effect var centerCell = swappedCellA && relevantMatchGroups.some(function (group) { return group.includes(swappedCellA); }) ? swappedCellA : swappedCellB; destroyCells(cellsToDestroy, centerCell); LK.setTimeout(function () { if (window.destructionInProgress || window.gravityInProgress || window.fillInProgress) { return; } var visibleMatchGroups = getMatches().filter(function (group) { // Check if the match has cells in both visible and invisible areas var visibleCells = group.filter(function (cell) { return cell.row >= extraRows; }); var invisibleCells = group.filter(function (cell) { return cell.row < extraRows; }); // Don't count groups with both visible and invisible cells where either group is just 1 cell if (visibleCells.length > 0 && invisibleCells.length > 0 && (visibleCells.length === 1 || invisibleCells.length === 1)) { return false; } return group.some(function (cell) { return cell.row >= extraRows; }); }); var newMatches = visibleMatchGroups; if (newMatches.length > 0) { var newCellsToDestroy = []; var newCellTracker = {}; newMatches.forEach(function (group) { group.forEach(function (cell) { var cellKey = cell.row + "_" + cell.col; if (!newCellTracker[cellKey] && cell.row >= extraRows && cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell) { newCellsToDestroy.push(cell); newCellTracker[cellKey] = true; } }); }); if (newCellsToDestroy.length) { destroyCells(newCellsToDestroy); } } }, 400); } } var gridSize = 8; var extraRows = 9; var cellSpacing = 10; var cellSize = 208; var gridCells = []; var totalGridWidth = gridSize * cellSize + (gridSize - 1) * cellSpacing; var totalVisibleGridHeight = totalGridWidth; var totalGridHeight = totalVisibleGridHeight + extraRows * (cellSize + cellSpacing); var startX = (2048 - totalGridWidth) / 2 + cellSize / 2; var startY = (-1300 - totalVisibleGridHeight) / 2 + cellSize / 2 + extraRows * (cellSize + cellSpacing); function getCellPosition(row, col) { return { x: startX + col * (cellSize + cellSpacing), y: startY + row * (cellSize + cellSpacing) - extraRows * (cellSize + cellSpacing) }; } var gridContainer = new Container(); game.addChild(gridContainer); function initializeGrid() { gridCells = []; for (var row = 0; row < gridSize + extraRows; row++) { gridCells[row] = []; for (var col = 0; col < gridSize; col++) { var pos = getCellPosition(row, col); var cell = getGridCell ? getGridCell() : new GridCell(); cell.x = pos.x; cell.y = pos.y; cell.row = row; cell.col = col; var randomValue; var attempts = 0; do { randomValue = Math.floor(Math.random() * 5) + 1; attempts++; var leftMatchCount = 0; var aboveMatchCount = 0; if (col >= 2) { if (gridCells[row][col - 1].value === randomValue && gridCells[row][col - 2].value === randomValue) { leftMatchCount = 2; } } if (row >= 2) { if (gridCells[row - 1][col].value === randomValue && gridCells[row - 2][col].value === randomValue) { aboveMatchCount = 2; } } } while ((leftMatchCount >= 2 || aboveMatchCount >= 2) && attempts < 10); cell.setValue(randomValue); if (row >= extraRows) { gridContainer.addChild(cell); } gridCells[row][col] = cell; } } } initializeGrid(); function ensureNoInitialMatches() { var matches = getMatches(); if (matches.length > 0) { matches.forEach(function (group) { group.forEach(function (cell) { var currentValue = cell.value; var newValue; do { newValue = Math.floor(Math.random() * 5) + 1; } while (newValue === currentValue); cell.setValue(newValue); }); }); ensureNoInitialMatches(); } } ensureNoInitialMatches();
===================================================================
--- original.js
+++ change.js
@@ -70,9 +70,8 @@
window.gravityInProgress = false;
window.fillInProgress = false;
window.destructionInProgress = false;
window.pendingDestructions = [];
-window.lastSwappedCells = null;
function handleCellTap(tappedCell) {
if (isAnimating || window.gravityInProgress || window.fillInProgress || window.destructionInProgress) {
return;
}
@@ -112,10 +111,8 @@
cell1.row = row2;
cell1.col = col2;
cell2.row = row1;
cell2.col = col1;
- // Store swapped cells for reference in destruction sequence
- window.lastSwappedCells = [cell1, cell2];
tween(cell1, {
x: pos2_x,
y: pos2_y
}, {
@@ -214,57 +211,28 @@
}
var visibleCellsToDestroy = cellsToDestroy.filter(function (cell) {
return cell.row >= extraRows && cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell;
});
- // Find the triggering cell (the one most recently moved or tapped)
- var originCell = selectedCell || (window.lastSwappedCells ? window.lastSwappedCells.find(function (cell) {
- return visibleCellsToDestroy.includes(cell);
- }) : null);
- // If no origin cell found, use first cell in the array
- if (!originCell && visibleCellsToDestroy.length > 0) {
- originCell = visibleCellsToDestroy[0];
+ // Find the center cell (the one that triggered the match)
+ var centerCell = null;
+ // If we have the cells from a swap, use one of those as the center
+ if (arguments.length > 1 && arguments[1]) {
+ centerCell = arguments[1];
+ } else if (cellsToDestroy.length > 0) {
+ // Otherwise use the middle cell of the match
+ centerCell = cellsToDestroy[Math.floor(cellsToDestroy.length / 2)];
}
- // Check if the origin cell is in the middle of the match
- var isMiddleCell = false;
- if (originCell && visibleCellsToDestroy.length >= 3) {
- // For horizontal matches
- var horizontalGroup = visibleCellsToDestroy.filter(function (cell) {
- return cell.row === originCell.row;
- }).sort(function (a, b) {
- return a.col - b.col;
- });
- // For vertical matches
- var verticalGroup = visibleCellsToDestroy.filter(function (cell) {
- return cell.col === originCell.col;
- }).sort(function (a, b) {
- return a.row - b.row;
- });
- // Check if origin is in the middle of a horizontal match
- if (horizontalGroup.length >= 3) {
- var middleIndex = Math.floor(horizontalGroup.length / 2);
- if (horizontalGroup[middleIndex] === originCell) {
- isMiddleCell = true;
- }
- }
- // Check if origin is in the middle of a vertical match
- if (verticalGroup.length >= 3) {
- var middleIndex = Math.floor(verticalGroup.length / 2);
- if (verticalGroup[middleIndex] === originCell) {
- isMiddleCell = true;
- }
- }
- }
- // Sort cells by distance from origin cell for sequential destruction
- if (originCell && !isMiddleCell) {
+ // Sort cells by distance from center cell for ripple effect
+ if (centerCell && visibleCellsToDestroy.length > 0) {
visibleCellsToDestroy.sort(function (a, b) {
- var distA = Math.sqrt(Math.pow(a.row - originCell.row, 2) + Math.pow(a.col - originCell.col, 2));
- var distB = Math.sqrt(Math.pow(b.row - originCell.row, 2) + Math.pow(b.col - originCell.col, 2));
+ var distA = Math.abs(a.row - centerCell.row) + Math.abs(a.col - centerCell.col);
+ var distB = Math.abs(b.row - centerCell.row) + Math.abs(b.col - centerCell.col);
return distA - distB;
});
}
var delay = 0;
- var delayIncrement = isMiddleCell ? 0 : 100; // No delay between explosions if middle cell
- var totalDestructionTime = isMiddleCell ? 200 : visibleCellsToDestroy.length * delayIncrement;
+ var delayIncrement = 100;
+ var totalDestructionTime = visibleCellsToDestroy.length * delayIncrement;
visibleCellsToDestroy.forEach(function (cell) {
LK.setTimeout(function () {
if (cell && gridCells[cell.row] && gridCells[cell.row][cell.col] === cell) {
LK.getSound('Explosion').play();
@@ -381,10 +349,9 @@
newCellsToAdd.push({
cell: newCell,
destY: pos.y,
row: row,
- col: col,
- isMiddleCell: false // Will check this later
+ col: col
});
if (row >= extraRows) {
gridContainer.addChild(newCell);
}
@@ -453,32 +420,16 @@
}
});
});
if (newCellsToDestroy.length) {
- // Find a trigger cell for cascading matches - use newly added cells as origin
- var originCells = newCellsToAdd.filter(function (cellData) {
- return newCellsToDestroy.some(function (cell) {
- return cell.row === cellData.row && cell.col === cellData.col;
- });
- });
- if (originCells.length > 0) {
- // Update lastSwappedCells to the newly added cells that caused matches
- window.lastSwappedCells = originCells.map(function (cellData) {
- return cellData.cell;
- });
- // Check if any new cell is in the middle of a match
- for (var i = 0; i < window.lastSwappedCells.length; i++) {
- var swappedCell = window.lastSwappedCells[i];
- for (var j = 0; j < newMatches.length; j++) {
- if (isMiddleOfMatch(swappedCell, newMatches[j])) {
- // Mark the cell as middle cell
- window.lastSwappedCells[i].isMiddleCell = true;
- break;
- }
- }
- }
+ // Find a central cell for the auto-match after gravity
+ var centerCell = null;
+ if (newMatches.length > 0 && newMatches[0].length > 0) {
+ // Pick the center of the first match group
+ var matchGroup = newMatches[0];
+ centerCell = matchGroup[Math.floor(matchGroup.length / 2)];
}
- destroyCells(newCellsToDestroy);
+ destroyCells(newCellsToDestroy, centerCell);
} else {
isAnimating = false;
}
} else {
@@ -489,51 +440,16 @@
window.fillInProgress = false;
isAnimating = false;
}
}
-function isMiddleOfMatch(cell, matchGroup) {
- if (!cell || !matchGroup || !matchGroup.length) {
- return false;
- }
- // For horizontal matches
- var horizontalGroup = matchGroup.filter(function (c) {
- return c.row === cell.row;
- }).sort(function (a, b) {
- return a.col - b.col;
- });
- // For vertical matches
- var verticalGroup = matchGroup.filter(function (c) {
- return c.col === cell.col;
- }).sort(function (a, b) {
- return a.row - b.row;
- });
- // Check if it's a match
- if (horizontalGroup.length >= 3) {
- var middleIndex = Math.floor(horizontalGroup.length / 2);
- if (horizontalGroup[middleIndex] === cell) {
- return true;
- }
- }
- if (verticalGroup.length >= 3) {
- var middleIndex = Math.floor(verticalGroup.length / 2);
- if (verticalGroup[middleIndex] === cell) {
- return true;
- }
- }
- return false;
-}
function checkForAndDestroyMatches(swappedCellA, swappedCellB) {
if (window.destructionInProgress || window.gravityInProgress || window.fillInProgress) {
return;
}
var allMatchGroupsOnBoard = getMatches();
if (!allMatchGroupsOnBoard.length) {
return;
}
- // Store swapped cells for sequential destruction
- if (swappedCellA && swappedCellB) {
- window.lastSwappedCells = [swappedCellA, swappedCellB];
- }
var relevantMatchGroups = allMatchGroupsOnBoard.filter(function (group) {
// Check if the match has cells in both visible and invisible areas
var visibleCells = group.filter(function (cell) {
return cell.row >= extraRows;
@@ -563,9 +479,13 @@
}
});
});
if (cellsToDestroy.length) {
- destroyCells(cellsToDestroy);
+ // Pass the swapped cell that created the match as the center for the ripple effect
+ var centerCell = swappedCellA && relevantMatchGroups.some(function (group) {
+ return group.includes(swappedCellA);
+ }) ? swappedCellA : swappedCellB;
+ destroyCells(cellsToDestroy, centerCell);
LK.setTimeout(function () {
if (window.destructionInProgress || window.gravityInProgress || window.fillInProgress) {
return;
}
la figura de una casa color blanca simple para una interfaz. In-Game asset. 2d. High contrast. No shadows
haz el fondo color morado
circular check logo. In-Game asset. 2d. High contrast. No shadows
Cuadrado con los bordes redondeado negro. In-Game asset. 2d. High contrast. No shadows
hazlo un gris claro
Que sea blanco
Que sea blanco