User prompt
CHANGE THE IMAGE OF POWER UP TO "Power"
User prompt
IF WE MATCH 4 CANDIES, A FIERY POWER UP WILL COME, MAKE A POWER PLACE AND POWER UP WILL GO THERE. WHEN WE CLICK ON POWER UP, 5 CANDIES WILL EXPLODES AT RANDOM βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
CHANGE EXPLOSION EFFECT WITH "exp" βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
CHANGE EXPLOSION EFFECT βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add explosion effect βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
IF WE DRAG THE CANDIES AND BRING THEM TO 3 JERSEYS SIDE BY SIDE, WE WILL GET POINTS, ADD POINT COUNTER
User prompt
WHY I CANNOT MATCH FIX Let's make a match by swiping
User prompt
BALLS CAME CLOSE TO THE SCREEN
User prompt
THE BALLS ARE TOO SMALL, MAKE THEM BIGGER
Code edit (1 edits merged)
Please save this source code
User prompt
Sweet Gem Crusher
Initial prompt
DO ME CAMDY CRUSH AND IT WILL BE THE SAME, NOTHING IS MISSING, LET IT BE POINTS, EVEN POINTS, EVEN A COMBO
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Candy = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.gridX = 0; self.gridY = 0; self.isMatched = false; var candyAsset = self.attachAsset('candy' + type, { anchorX: 0.5, anchorY: 0.5 }); self.setGridPosition = function (gridX, gridY) { self.gridX = gridX; self.gridY = gridY; self.x = GRID_START_X + gridX * CELL_SIZE + CELL_SIZE / 2; self.y = GRID_START_Y + gridY * CELL_SIZE + CELL_SIZE / 2; }; self.animateToGridPosition = function (gridX, gridY, duration) { self.gridX = gridX; self.gridY = gridY; var targetX = GRID_START_X + gridX * CELL_SIZE + CELL_SIZE / 2; var targetY = GRID_START_Y + gridY * CELL_SIZE + CELL_SIZE / 2; tween(self, { x: targetX, y: targetY }, { duration: duration || 300, easing: tween.easeOut }); }; self.highlight = function () { tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut }); }; self.unhighlight = function () { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeOut }); }; self.markForRemoval = function () { self.isMatched = true; tween(self, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 250, easing: tween.easeIn }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2C1810 }); /**** * Game Code ****/ var GRID_SIZE = 8; var CELL_SIZE = 130; var GRID_START_X = (2048 - GRID_SIZE * CELL_SIZE) / 2; var GRID_START_Y = (2732 - GRID_SIZE * CELL_SIZE) / 2 - 200; var grid = []; var candies = []; var selectedCandy = null; var isProcessing = false; var gameScore = 0; var comboMultiplier = 1; // Initialize grid background var gridBackground = game.addChild(LK.getAsset('gridBg', { anchorX: 0.5, anchorY: 0.5 })); gridBackground.x = 2048 / 2; gridBackground.y = GRID_START_Y + GRID_SIZE * CELL_SIZE / 2; // Create cell backgrounds for (var i = 0; i < GRID_SIZE; i++) { for (var j = 0; j < GRID_SIZE; j++) { var cellBg = game.addChild(LK.getAsset('cellBg', { anchorX: 0.5, anchorY: 0.5 })); cellBg.x = GRID_START_X + i * CELL_SIZE + CELL_SIZE / 2; cellBg.y = GRID_START_Y + j * CELL_SIZE + CELL_SIZE / 2; } } // Initialize score display var scoreText = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); scoreText.y = 50; LK.gui.top.addChild(scoreText); // Initialize combo display var comboText = new Text2('', { size: 50, fill: 0xFFD700 }); comboText.anchor.set(0.5, 0); comboText.y = 140; LK.gui.top.addChild(comboText); // Initialize grid array function initializeGrid() { grid = []; for (var i = 0; i < GRID_SIZE; i++) { grid[i] = []; for (var j = 0; j < GRID_SIZE; j++) { grid[i][j] = null; } } } // Generate random candy type function getRandomCandyType() { return Math.floor(Math.random() * 6) + 1; } // Create candy at grid position function createCandy(gridX, gridY) { var candyType = getRandomCandyType(); var candy = new Candy(candyType); candy.setGridPosition(gridX, gridY); game.addChild(candy); candies.push(candy); grid[gridX][gridY] = candy; return candy; } // Fill grid with initial candies function fillGrid() { for (var i = 0; i < GRID_SIZE; i++) { for (var j = 0; j < GRID_SIZE; j++) { if (!grid[i][j]) { createCandy(i, j); } } } } // Check if coordinates are valid function isValidPosition(x, y) { return x >= 0 && x < GRID_SIZE && y >= 0 && y < GRID_SIZE; } // Check if two positions are adjacent function areAdjacent(x1, y1, x2, y2) { var dx = Math.abs(x1 - x2); var dy = Math.abs(y1 - y2); return dx === 1 && dy === 0 || dx === 0 && dy === 1; } // Swap two candies function swapCandies(candy1, candy2) { if (!candy1 || !candy2) return; var tempX = candy1.gridX; var tempY = candy1.gridY; grid[candy1.gridX][candy1.gridY] = candy2; grid[candy2.gridX][candy2.gridY] = candy1; candy1.animateToGridPosition(candy2.gridX, candy2.gridY); candy2.animateToGridPosition(tempX, tempY); LK.getSound('swap').play(); } // Find matches in a line function findMatches(startX, startY, deltaX, deltaY) { var matches = []; var currentCandy = grid[startX][startY]; if (!currentCandy) return matches; var count = 1; matches.push(currentCandy); // Check forward var x = startX + deltaX; var y = startY + deltaY; while (isValidPosition(x, y) && grid[x][y] && grid[x][y].type === currentCandy.type) { matches.push(grid[x][y]); count++; x += deltaX; y += deltaY; } // Check backward x = startX - deltaX; y = startY - deltaY; while (isValidPosition(x, y) && grid[x][y] && grid[x][y].type === currentCandy.type) { matches.unshift(grid[x][y]); count++; x -= deltaX; y -= deltaY; } return count >= 3 ? matches : []; } // Find all matches on the board function findAllMatches() { var allMatches = []; var processed = []; for (var i = 0; i < GRID_SIZE; i++) { processed[i] = []; for (var j = 0; j < GRID_SIZE; j++) { processed[i][j] = false; } } for (var i = 0; i < GRID_SIZE; i++) { for (var j = 0; j < GRID_SIZE; j++) { if (grid[i][j] && !processed[i][j]) { // Check horizontal matches var horizontalMatches = findMatches(i, j, 1, 0); if (horizontalMatches.length >= 3) { for (var k = 0; k < horizontalMatches.length; k++) { var candy = horizontalMatches[k]; processed[candy.gridX][candy.gridY] = true; if (allMatches.indexOf(candy) === -1) { allMatches.push(candy); } } } // Check vertical matches var verticalMatches = findMatches(i, j, 0, 1); if (verticalMatches.length >= 3) { for (var k = 0; k < verticalMatches.length; k++) { var candy = verticalMatches[k]; processed[candy.gridX][candy.gridY] = true; if (allMatches.indexOf(candy) === -1) { allMatches.push(candy); } } } } } } return allMatches; } // Remove matched candies function removeMatches(matches) { for (var i = 0; i < matches.length; i++) { var candy = matches[i]; // Create explosion effect tween(candy, { scaleX: 1.8, scaleY: 1.8, rotation: Math.PI * 2, alpha: 0.3 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { // Second phase - shrink and fade out tween(candy, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 150, easing: tween.easeIn }); } }); grid[candy.gridX][candy.gridY] = null; // Remove from candies array var index = candies.indexOf(candy); if (index > -1) { candies.splice(index, 1); } } // Calculate score var baseScore = matches.length * 10; var bonusScore = matches.length > 3 ? (matches.length - 3) * 20 : 0; var totalScore = (baseScore + bonusScore) * comboMultiplier; gameScore += totalScore; scoreText.setText('Score: ' + gameScore); LK.setScore(gameScore); // Show combo feedback if (comboMultiplier > 1) { comboText.setText('COMBO x' + comboMultiplier + ' (+' + totalScore + ')'); comboText.alpha = 1; tween(comboText, { alpha: 0 }, { duration: 1000, easing: tween.easeOut }); } else { comboText.setText(''); } // Flash screen effect for big matches if (matches.length >= 5) { LK.effects.flashScreen(0xFFD700, 300); } LK.getSound('match').play(); // Schedule removal after explosion animation LK.setTimeout(function () { for (var i = 0; i < matches.length; i++) { matches[i].destroy(); } }, 350); } // Make candies fall down function applyGravity() { var moved = false; for (var i = 0; i < GRID_SIZE; i++) { for (var j = GRID_SIZE - 2; j >= 0; j--) { if (grid[i][j]) { var fallDistance = 0; var checkY = j + 1; while (checkY < GRID_SIZE && !grid[i][checkY]) { fallDistance++; checkY++; } if (fallDistance > 0) { var candy = grid[i][j]; grid[i][j] = null; grid[i][j + fallDistance] = candy; candy.animateToGridPosition(i, j + fallDistance); moved = true; } } } } return moved; } // Fill empty spaces with new candies function fillEmptySpaces() { var added = false; for (var i = 0; i < GRID_SIZE; i++) { for (var j = 0; j < GRID_SIZE; j++) { if (!grid[i][j]) { var candy = createCandy(i, j); // Start candy above the grid and animate down candy.y = GRID_START_Y - 100; candy.animateToGridPosition(i, j); added = true; } } } return added; } // Check if move creates matches function wouldCreateMatch(candy1, candy2) { // Store original positions var origX1 = candy1.gridX; var origY1 = candy1.gridY; var origX2 = candy2.gridX; var origY2 = candy2.gridY; // Temporarily swap in grid grid[candy1.gridX][candy1.gridY] = candy2; grid[candy2.gridX][candy2.gridY] = candy1; // Temporarily swap candy positions candy1.gridX = origX2; candy1.gridY = origY2; candy2.gridX = origX1; candy2.gridY = origY1; var matches1 = findMatches(candy1.gridX, candy1.gridY, 1, 0); var matches2 = findMatches(candy1.gridX, candy1.gridY, 0, 1); var matches3 = findMatches(candy2.gridX, candy2.gridY, 1, 0); var matches4 = findMatches(candy2.gridX, candy2.gridY, 0, 1); var hasMatch = matches1.length >= 3 || matches2.length >= 3 || matches3.length >= 3 || matches4.length >= 3; // Restore original positions candy1.gridX = origX1; candy1.gridY = origY1; candy2.gridX = origX2; candy2.gridY = origY2; grid[origX1][origY1] = candy1; grid[origX2][origY2] = candy2; return hasMatch; } // Process matches and cascades function processMatches() { if (isProcessing) return; isProcessing = true; var matches = findAllMatches(); if (matches.length > 0) { removeMatches(matches); comboMultiplier++; LK.setTimeout(function () { var gravityApplied = applyGravity(); var spacesAdded = fillEmptySpaces(); if (gravityApplied || spacesAdded) { LK.setTimeout(function () { isProcessing = false; processMatches(); // Check for new matches }, 400); } else { isProcessing = false; comboMultiplier = 1; } }, 400); } else { isProcessing = false; comboMultiplier = 1; } } // Get candy at screen position function getCandyAt(x, y) { // Calculate grid coordinates from screen position var gridX = Math.floor((x - GRID_START_X) / CELL_SIZE); var gridY = Math.floor((y - GRID_START_Y) / CELL_SIZE); // Check if coordinates are within grid bounds if (gridX >= 0 && gridX < GRID_SIZE && gridY >= 0 && gridY < GRID_SIZE) { return grid[gridX][gridY]; } return null; } var dragStartCandy = null; var dragCurrentCandy = null; // Game input handling game.down = function (x, y, obj) { if (isProcessing) return; var candy = getCandyAt(x, y); if (candy) { dragStartCandy = candy; dragCurrentCandy = candy; candy.highlight(); } }; game.move = function (x, y, obj) { if (isProcessing || !dragStartCandy) return; var candy = getCandyAt(x, y); if (candy && candy !== dragCurrentCandy) { if (dragCurrentCandy && dragCurrentCandy !== dragStartCandy) { dragCurrentCandy.unhighlight(); } dragCurrentCandy = candy; if (candy !== dragStartCandy) { candy.highlight(); } } }; game.up = function (x, y, obj) { if (isProcessing || !dragStartCandy) return; var endCandy = getCandyAt(x, y); if (endCandy && endCandy !== dragStartCandy && areAdjacent(dragStartCandy.gridX, dragStartCandy.gridY, endCandy.gridX, endCandy.gridY)) { if (wouldCreateMatch(dragStartCandy, endCandy)) { swapCandies(dragStartCandy, endCandy); LK.setTimeout(function () { processMatches(); }, 400); } else { // Invalid move - swap back dragStartCandy.unhighlight(); if (endCandy) endCandy.unhighlight(); } } else { // No valid target - just unhighlight dragStartCandy.unhighlight(); if (dragCurrentCandy && dragCurrentCandy !== dragStartCandy) { dragCurrentCandy.unhighlight(); } } dragStartCandy = null; dragCurrentCandy = null; }; // Initialize game initializeGrid(); fillGrid(); // Remove initial matches LK.setTimeout(function () { processMatches(); }, 100); game.update = function () { // Game runs automatically through event handling };
===================================================================
--- original.js
+++ change.js
@@ -246,9 +246,29 @@
// Remove matched candies
function removeMatches(matches) {
for (var i = 0; i < matches.length; i++) {
var candy = matches[i];
- candy.markForRemoval();
+ // Create explosion effect
+ tween(candy, {
+ scaleX: 1.8,
+ scaleY: 1.8,
+ rotation: Math.PI * 2,
+ alpha: 0.3
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ // Second phase - shrink and fade out
+ tween(candy, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 150,
+ easing: tween.easeIn
+ });
+ }
+ });
grid[candy.gridX][candy.gridY] = null;
// Remove from candies array
var index = candies.indexOf(candy);
if (index > -1) {
@@ -279,14 +299,14 @@
if (matches.length >= 5) {
LK.effects.flashScreen(0xFFD700, 300);
}
LK.getSound('match').play();
- // Schedule removal after animation
+ // Schedule removal after explosion animation
LK.setTimeout(function () {
for (var i = 0; i < matches.length; i++) {
matches[i].destroy();
}
- }, 300);
+ }, 350);
}
// Make candies fall down
function applyGravity() {
var moved = false;