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 = 90; 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: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // 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]; candy.markForRemoval(); 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); LK.getSound('match').play(); // Schedule removal after animation LK.setTimeout(function () { for (var i = 0; i < matches.length; i++) { matches[i].destroy(); } }, 300); } // 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) { // Temporarily swap var tempX = candy1.gridX; var tempY = candy1.gridY; grid[candy1.gridX][candy1.gridY] = candy2; grid[candy2.gridX][candy2.gridY] = candy1; candy1.gridX = candy2.gridX; candy1.gridY = candy2.gridY; candy2.gridX = tempX; candy2.gridY = tempY; 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; // Swap back grid[candy2.gridX][candy2.gridY] = candy1; grid[candy1.gridX][candy1.gridY] = candy2; candy2.gridX = candy1.gridX; candy2.gridY = candy1.gridY; candy1.gridX = tempX; candy1.gridY = tempY; 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) { for (var i = 0; i < candies.length; i++) { var candy = candies[i]; var bounds = candy.getBounds(); if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) { return candy; } } return null; } // Game input handling game.down = function (x, y, obj) { if (isProcessing) return; var candy = getCandyAt(x, y); if (candy) { if (selectedCandy) { if (selectedCandy === candy) { selectedCandy.unhighlight(); selectedCandy = null; } else if (areAdjacent(selectedCandy.gridX, selectedCandy.gridY, candy.gridX, candy.gridY)) { if (wouldCreateMatch(selectedCandy, candy)) { swapCandies(selectedCandy, candy); selectedCandy.unhighlight(); selectedCandy = null; LK.setTimeout(function () { processMatches(); }, 400); } else { selectedCandy.unhighlight(); selectedCandy = candy; candy.highlight(); } } else { selectedCandy.unhighlight(); selectedCandy = candy; candy.highlight(); } } else { selectedCandy = candy; candy.highlight(); } } }; // 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
@@ -1,6 +1,408 @@
-/****
+/****
+* 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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2C1810
+});
+
+/****
+* Game Code
+****/
+var GRID_SIZE = 8;
+var CELL_SIZE = 90;
+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: 60,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+// 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];
+ candy.markForRemoval();
+ 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);
+ LK.getSound('match').play();
+ // Schedule removal after animation
+ LK.setTimeout(function () {
+ for (var i = 0; i < matches.length; i++) {
+ matches[i].destroy();
+ }
+ }, 300);
+}
+// 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) {
+ // Temporarily swap
+ var tempX = candy1.gridX;
+ var tempY = candy1.gridY;
+ grid[candy1.gridX][candy1.gridY] = candy2;
+ grid[candy2.gridX][candy2.gridY] = candy1;
+ candy1.gridX = candy2.gridX;
+ candy1.gridY = candy2.gridY;
+ candy2.gridX = tempX;
+ candy2.gridY = tempY;
+ 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;
+ // Swap back
+ grid[candy2.gridX][candy2.gridY] = candy1;
+ grid[candy1.gridX][candy1.gridY] = candy2;
+ candy2.gridX = candy1.gridX;
+ candy2.gridY = candy1.gridY;
+ candy1.gridX = tempX;
+ candy1.gridY = tempY;
+ 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) {
+ for (var i = 0; i < candies.length; i++) {
+ var candy = candies[i];
+ var bounds = candy.getBounds();
+ if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
+ return candy;
+ }
+ }
+ return null;
+}
+// Game input handling
+game.down = function (x, y, obj) {
+ if (isProcessing) return;
+ var candy = getCandyAt(x, y);
+ if (candy) {
+ if (selectedCandy) {
+ if (selectedCandy === candy) {
+ selectedCandy.unhighlight();
+ selectedCandy = null;
+ } else if (areAdjacent(selectedCandy.gridX, selectedCandy.gridY, candy.gridX, candy.gridY)) {
+ if (wouldCreateMatch(selectedCandy, candy)) {
+ swapCandies(selectedCandy, candy);
+ selectedCandy.unhighlight();
+ selectedCandy = null;
+ LK.setTimeout(function () {
+ processMatches();
+ }, 400);
+ } else {
+ selectedCandy.unhighlight();
+ selectedCandy = candy;
+ candy.highlight();
+ }
+ } else {
+ selectedCandy.unhighlight();
+ selectedCandy = candy;
+ candy.highlight();
+ }
+ } else {
+ selectedCandy = candy;
+ candy.highlight();
+ }
+ }
+};
+// Initialize game
+initializeGrid();
+fillGrid();
+// Remove initial matches
+LK.setTimeout(function () {
+ processMatches();
+}, 100);
+game.update = function () {
+ // Game runs automatically through event handling
+};
\ No newline at end of file