User prompt
17. Satırı düzelt yoksa ananı sikerim ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
L17 plugins load ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
17 düzelt yoksa ananı sikerim ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
17. Satıtı düzelt yoksa ananı sikerim ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
17 ve 37 düzelt yoksa ananı sikerim ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Düzelt kodları ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Düzelt kodları ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
L37 and l17 fix ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught ReferenceError: tween is not defined' in or related to this line: 'tween(self, {' Line Number: 37 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
L17 düzenle
User prompt
17. Satırı düzenle
User prompt
17 satırdaki kodu eklentileri yükle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
17 satırdaki kodu eklentileri yükle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Eklentileri yükle ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Ha bide bunlara patlama efekti ekleyelim ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Tamam ama şeker patlatdığım zamam şekerlerde daire oluşuyor onu düzelt
User prompt
Parmağımla şekerleri sürükleyebileyim
User prompt
Mobil için
Code edit (1 edits merged)
Please save this source code
User prompt
Sweet Crush Match
Initial prompt
Bana candy crush benzeri şeker patlatma oyunu yap
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Candy = Container.expand(function (type) {
var self = Container.call(this);
self.candyType = type;
self.gridX = 0;
self.gridY = 0;
self.isAnimating = false;
self.isMatched = false;
var candyAssets = ['candy_red', 'candy_blue', 'candy_green', 'candy_yellow', 'candy_purple', 'candy_orange'];
var candyGraphics = self.attachAsset(candyAssets[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.animateToPosition = function (targetX, targetY, duration, onComplete) {
self.isAnimating = true;
tween(self, {
x: targetX,
y: targetY
}, {
duration: duration || 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isAnimating = false;
if (onComplete) onComplete();
}
});
};
self.animateMatch = function (onComplete) {
self.isMatched = true;
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 200,
easing: tween.easeIn,
onFinish: onComplete
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1A1A2E
});
/****
* Game Code
****/
// Game constants
var GRID_SIZE = 8;
var CELL_SIZE = 200;
var GRID_START_X = (2048 - GRID_SIZE * CELL_SIZE) / 2;
var GRID_START_Y = 400;
var CANDY_TYPES = 6;
// Game variables
var grid = [];
var selectedCandy = null;
var isProcessing = false;
var score = 0;
var moves = 30;
var targetScore = 5000;
// Initialize UI
var scoreText = new Text2('Score: 0', {
size: 80,
fill: '#FFFFFF'
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var movesText = new Text2('Moves: 30', {
size: 80,
fill: '#FFFFFF'
});
movesText.anchor.set(0.5, 0);
movesText.y = 100;
LK.gui.top.addChild(movesText);
var targetText = new Text2('Target: 5000', {
size: 60,
fill: '#FFD700'
});
targetText.anchor.set(0.5, 0);
targetText.y = 200;
LK.gui.top.addChild(targetText);
// Initialize grid
function initializeGrid() {
grid = [];
for (var x = 0; x < GRID_SIZE; x++) {
grid[x] = [];
for (var y = 0; y < GRID_SIZE; y++) {
var candyType = Math.floor(Math.random() * CANDY_TYPES);
var candy = new Candy(candyType);
candy.setGridPosition(x, y);
grid[x][y] = candy;
game.addChild(candy);
}
}
// Remove initial matches
removeInitialMatches();
}
function removeInitialMatches() {
var hasMatches = true;
while (hasMatches) {
var matches = findAllMatches();
if (matches.length === 0) {
hasMatches = false;
} else {
for (var i = 0; i < matches.length; i++) {
var match = matches[i];
var newType = Math.floor(Math.random() * CANDY_TYPES);
match.candyType = newType;
match.removeChild(match.children[0]);
var candyAssets = ['candy_red', 'candy_blue', 'candy_green', 'candy_yellow', 'candy_purple', 'candy_orange'];
match.attachAsset(candyAssets[newType], {
anchorX: 0.5,
anchorY: 0.5
});
}
}
}
}
function getCandyAt(x, y) {
if (x < 0 || x >= GRID_SIZE || y < 0 || y >= GRID_SIZE) return null;
return grid[x][y];
}
function swapCandies(candy1, candy2) {
if (!candy1 || !candy2 || candy1.isAnimating || candy2.isAnimating) return false;
var tempX = candy1.gridX;
var tempY = candy1.gridY;
// Update grid positions
grid[candy1.gridX][candy1.gridY] = candy2;
grid[candy2.gridX][candy2.gridY] = candy1;
// Update candy grid positions
candy1.setGridPosition(candy2.gridX, candy2.gridY);
candy2.setGridPosition(tempX, tempY);
return true;
}
function findMatches(startX, startY) {
var candy = getCandyAt(startX, startY);
if (!candy) return [];
var matches = [];
var type = candy.candyType;
// Check horizontal matches
var horizontalMatches = [candy];
// Check left
for (var x = startX - 1; x >= 0; x--) {
var leftCandy = getCandyAt(x, startY);
if (leftCandy && leftCandy.candyType === type) {
horizontalMatches.unshift(leftCandy);
} else {
break;
}
}
// Check right
for (var x = startX + 1; x < GRID_SIZE; x++) {
var rightCandy = getCandyAt(x, startY);
if (rightCandy && rightCandy.candyType === type) {
horizontalMatches.push(rightCandy);
} else {
break;
}
}
if (horizontalMatches.length >= 3) {
matches = matches.concat(horizontalMatches);
}
// Check vertical matches
var verticalMatches = [candy];
// Check up
for (var y = startY - 1; y >= 0; y--) {
var upCandy = getCandyAt(startX, y);
if (upCandy && upCandy.candyType === type) {
verticalMatches.unshift(upCandy);
} else {
break;
}
}
// Check down
for (var y = startY + 1; y < GRID_SIZE; y++) {
var downCandy = getCandyAt(startX, y);
if (downCandy && downCandy.candyType === type) {
verticalMatches.push(downCandy);
} else {
break;
}
}
if (verticalMatches.length >= 3) {
matches = matches.concat(verticalMatches);
}
// Remove duplicates
var uniqueMatches = [];
for (var i = 0; i < matches.length; i++) {
var found = false;
for (var j = 0; j < uniqueMatches.length; j++) {
if (matches[i] === uniqueMatches[j]) {
found = true;
break;
}
}
if (!found) {
uniqueMatches.push(matches[i]);
}
}
return uniqueMatches;
}
function findAllMatches() {
var allMatches = [];
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = 0; y < GRID_SIZE; y++) {
var matches = findMatches(x, y);
for (var i = 0; i < matches.length; i++) {
var found = false;
for (var j = 0; j < allMatches.length; j++) {
if (matches[i] === allMatches[j]) {
found = true;
break;
}
}
if (!found) {
allMatches.push(matches[i]);
}
}
}
}
return allMatches;
}
function removeMatches(matches) {
if (matches.length === 0) return;
// Calculate points
var points = 0;
if (matches.length === 3) points = 100;else if (matches.length === 4) points = 200;else points = 500;
score += points;
scoreText.setText('Score: ' + score);
// Play match sound
LK.getSound('match').play();
// Animate candies disappearing
var animationsComplete = 0;
for (var i = 0; i < matches.length; i++) {
var candy = matches[i];
grid[candy.gridX][candy.gridY] = null;
candy.animateMatch(function () {
animationsComplete++;
if (animationsComplete === matches.length) {
applyGravity();
}
});
}
}
function applyGravity() {
var needsGravity = false;
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = GRID_SIZE - 1; y >= 0; y--) {
if (grid[x][y] === null) {
// Find candy above
for (var searchY = y - 1; searchY >= 0; searchY--) {
if (grid[x][searchY] !== null) {
var candy = grid[x][searchY];
grid[x][y] = candy;
grid[x][searchY] = null;
candy.gridY = y;
var targetY = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
candy.animateToPosition(candy.x, targetY, 300);
needsGravity = true;
break;
}
}
}
}
}
// Spawn new candies
for (var x = 0; x < GRID_SIZE; x++) {
for (var y = 0; y < GRID_SIZE; y++) {
if (grid[x][y] === null) {
var candyType = Math.floor(Math.random() * CANDY_TYPES);
var candy = new Candy(candyType);
candy.setGridPosition(x, y);
candy.y = GRID_START_Y - CELL_SIZE;
var targetY = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
candy.animateToPosition(candy.x, targetY, 400);
grid[x][y] = candy;
game.addChild(candy);
needsGravity = true;
}
}
}
if (needsGravity) {
LK.setTimeout(function () {
checkForMatches();
}, 500);
} else {
isProcessing = false;
}
}
function checkForMatches() {
var matches = findAllMatches();
if (matches.length > 0) {
removeMatches(matches);
} else {
isProcessing = false;
}
}
function isAdjacent(candy1, candy2) {
var dx = Math.abs(candy1.gridX - candy2.gridX);
var dy = Math.abs(candy1.gridY - candy2.gridY);
return dx === 1 && dy === 0 || dx === 0 && dy === 1;
}
function getCandyAtPosition(x, y) {
for (var gx = 0; gx < GRID_SIZE; gx++) {
for (var gy = 0; gy < GRID_SIZE; gy++) {
var candy = grid[gx][gy];
if (candy && !candy.isMatched) {
var candyBounds = {
x: candy.x - CELL_SIZE / 2,
y: candy.y - CELL_SIZE / 2,
width: CELL_SIZE,
height: CELL_SIZE
};
if (x >= candyBounds.x && x <= candyBounds.x + candyBounds.width && y >= candyBounds.y && y <= candyBounds.y + candyBounds.height) {
return candy;
}
}
}
}
return null;
}
// Game event handlers
game.down = function (x, y, obj) {
if (isProcessing) return;
var candy = getCandyAtPosition(x, y);
if (candy) {
if (selectedCandy) {
selectedCandy.alpha = 1.0;
}
selectedCandy = candy;
candy.alpha = 0.7;
}
};
game.up = function (x, y, obj) {
if (isProcessing || !selectedCandy) return;
var targetCandy = getCandyAtPosition(x, y);
if (targetCandy && targetCandy !== selectedCandy && isAdjacent(selectedCandy, targetCandy)) {
isProcessing = true;
// Try the swap
var candy1 = selectedCandy;
var candy2 = targetCandy;
if (swapCandies(candy1, candy2)) {
LK.getSound('swap').play();
// Animate the swap
var targetX1 = candy1.x;
var targetY1 = candy1.y;
var targetX2 = candy2.x;
var targetY2 = candy2.y;
candy1.animateToPosition(targetX1, targetY1, 200);
candy2.animateToPosition(targetX2, targetY2, 200, function () {
// Check for matches after swap
var matches1 = findMatches(candy1.gridX, candy1.gridY);
var matches2 = findMatches(candy2.gridX, candy2.gridY);
var allSwapMatches = matches1.concat(matches2);
// Remove duplicates
var uniqueMatches = [];
for (var i = 0; i < allSwapMatches.length; i++) {
var found = false;
for (var j = 0; j < uniqueMatches.length; j++) {
if (allSwapMatches[i] === uniqueMatches[j]) {
found = true;
break;
}
}
if (!found) {
uniqueMatches.push(allSwapMatches[i]);
}
}
if (uniqueMatches.length > 0) {
moves--;
movesText.setText('Moves: ' + moves);
removeMatches(uniqueMatches);
} else {
// Invalid move, swap back
swapCandies(candy1, candy2);
candy1.animateToPosition(targetX2, targetY2, 200);
candy2.animateToPosition(targetX1, targetY1, 200, function () {
isProcessing = false;
});
}
});
} else {
isProcessing = false;
}
}
if (selectedCandy) {
selectedCandy.alpha = 1.0;
selectedCandy = null;
}
};
// Game update loop
game.update = function () {
// Check win condition
if (score >= targetScore) {
LK.showYouWin();
}
// Check lose condition
if (moves <= 0 && score < targetScore) {
LK.showGameOver();
}
};
// Initialize the game
initializeGrid(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,421 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Candy = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.candyType = type;
+ self.gridX = 0;
+ self.gridY = 0;
+ self.isAnimating = false;
+ self.isMatched = false;
+ var candyAssets = ['candy_red', 'candy_blue', 'candy_green', 'candy_yellow', 'candy_purple', 'candy_orange'];
+ var candyGraphics = self.attachAsset(candyAssets[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.animateToPosition = function (targetX, targetY, duration, onComplete) {
+ self.isAnimating = true;
+ tween(self, {
+ x: targetX,
+ y: targetY
+ }, {
+ duration: duration || 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ if (onComplete) onComplete();
+ }
+ });
+ };
+ self.animateMatch = function (onComplete) {
+ self.isMatched = true;
+ tween(self, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 200,
+ easing: tween.easeIn,
+ onFinish: onComplete
+ });
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1A1A2E
+});
+
+/****
+* Game Code
+****/
+// Game constants
+var GRID_SIZE = 8;
+var CELL_SIZE = 200;
+var GRID_START_X = (2048 - GRID_SIZE * CELL_SIZE) / 2;
+var GRID_START_Y = 400;
+var CANDY_TYPES = 6;
+// Game variables
+var grid = [];
+var selectedCandy = null;
+var isProcessing = false;
+var score = 0;
+var moves = 30;
+var targetScore = 5000;
+// Initialize UI
+var scoreText = new Text2('Score: 0', {
+ size: 80,
+ fill: '#FFFFFF'
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+var movesText = new Text2('Moves: 30', {
+ size: 80,
+ fill: '#FFFFFF'
+});
+movesText.anchor.set(0.5, 0);
+movesText.y = 100;
+LK.gui.top.addChild(movesText);
+var targetText = new Text2('Target: 5000', {
+ size: 60,
+ fill: '#FFD700'
+});
+targetText.anchor.set(0.5, 0);
+targetText.y = 200;
+LK.gui.top.addChild(targetText);
+// Initialize grid
+function initializeGrid() {
+ grid = [];
+ for (var x = 0; x < GRID_SIZE; x++) {
+ grid[x] = [];
+ for (var y = 0; y < GRID_SIZE; y++) {
+ var candyType = Math.floor(Math.random() * CANDY_TYPES);
+ var candy = new Candy(candyType);
+ candy.setGridPosition(x, y);
+ grid[x][y] = candy;
+ game.addChild(candy);
+ }
+ }
+ // Remove initial matches
+ removeInitialMatches();
+}
+function removeInitialMatches() {
+ var hasMatches = true;
+ while (hasMatches) {
+ var matches = findAllMatches();
+ if (matches.length === 0) {
+ hasMatches = false;
+ } else {
+ for (var i = 0; i < matches.length; i++) {
+ var match = matches[i];
+ var newType = Math.floor(Math.random() * CANDY_TYPES);
+ match.candyType = newType;
+ match.removeChild(match.children[0]);
+ var candyAssets = ['candy_red', 'candy_blue', 'candy_green', 'candy_yellow', 'candy_purple', 'candy_orange'];
+ match.attachAsset(candyAssets[newType], {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ }
+ }
+}
+function getCandyAt(x, y) {
+ if (x < 0 || x >= GRID_SIZE || y < 0 || y >= GRID_SIZE) return null;
+ return grid[x][y];
+}
+function swapCandies(candy1, candy2) {
+ if (!candy1 || !candy2 || candy1.isAnimating || candy2.isAnimating) return false;
+ var tempX = candy1.gridX;
+ var tempY = candy1.gridY;
+ // Update grid positions
+ grid[candy1.gridX][candy1.gridY] = candy2;
+ grid[candy2.gridX][candy2.gridY] = candy1;
+ // Update candy grid positions
+ candy1.setGridPosition(candy2.gridX, candy2.gridY);
+ candy2.setGridPosition(tempX, tempY);
+ return true;
+}
+function findMatches(startX, startY) {
+ var candy = getCandyAt(startX, startY);
+ if (!candy) return [];
+ var matches = [];
+ var type = candy.candyType;
+ // Check horizontal matches
+ var horizontalMatches = [candy];
+ // Check left
+ for (var x = startX - 1; x >= 0; x--) {
+ var leftCandy = getCandyAt(x, startY);
+ if (leftCandy && leftCandy.candyType === type) {
+ horizontalMatches.unshift(leftCandy);
+ } else {
+ break;
+ }
+ }
+ // Check right
+ for (var x = startX + 1; x < GRID_SIZE; x++) {
+ var rightCandy = getCandyAt(x, startY);
+ if (rightCandy && rightCandy.candyType === type) {
+ horizontalMatches.push(rightCandy);
+ } else {
+ break;
+ }
+ }
+ if (horizontalMatches.length >= 3) {
+ matches = matches.concat(horizontalMatches);
+ }
+ // Check vertical matches
+ var verticalMatches = [candy];
+ // Check up
+ for (var y = startY - 1; y >= 0; y--) {
+ var upCandy = getCandyAt(startX, y);
+ if (upCandy && upCandy.candyType === type) {
+ verticalMatches.unshift(upCandy);
+ } else {
+ break;
+ }
+ }
+ // Check down
+ for (var y = startY + 1; y < GRID_SIZE; y++) {
+ var downCandy = getCandyAt(startX, y);
+ if (downCandy && downCandy.candyType === type) {
+ verticalMatches.push(downCandy);
+ } else {
+ break;
+ }
+ }
+ if (verticalMatches.length >= 3) {
+ matches = matches.concat(verticalMatches);
+ }
+ // Remove duplicates
+ var uniqueMatches = [];
+ for (var i = 0; i < matches.length; i++) {
+ var found = false;
+ for (var j = 0; j < uniqueMatches.length; j++) {
+ if (matches[i] === uniqueMatches[j]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ uniqueMatches.push(matches[i]);
+ }
+ }
+ return uniqueMatches;
+}
+function findAllMatches() {
+ var allMatches = [];
+ for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = 0; y < GRID_SIZE; y++) {
+ var matches = findMatches(x, y);
+ for (var i = 0; i < matches.length; i++) {
+ var found = false;
+ for (var j = 0; j < allMatches.length; j++) {
+ if (matches[i] === allMatches[j]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ allMatches.push(matches[i]);
+ }
+ }
+ }
+ }
+ return allMatches;
+}
+function removeMatches(matches) {
+ if (matches.length === 0) return;
+ // Calculate points
+ var points = 0;
+ if (matches.length === 3) points = 100;else if (matches.length === 4) points = 200;else points = 500;
+ score += points;
+ scoreText.setText('Score: ' + score);
+ // Play match sound
+ LK.getSound('match').play();
+ // Animate candies disappearing
+ var animationsComplete = 0;
+ for (var i = 0; i < matches.length; i++) {
+ var candy = matches[i];
+ grid[candy.gridX][candy.gridY] = null;
+ candy.animateMatch(function () {
+ animationsComplete++;
+ if (animationsComplete === matches.length) {
+ applyGravity();
+ }
+ });
+ }
+}
+function applyGravity() {
+ var needsGravity = false;
+ for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = GRID_SIZE - 1; y >= 0; y--) {
+ if (grid[x][y] === null) {
+ // Find candy above
+ for (var searchY = y - 1; searchY >= 0; searchY--) {
+ if (grid[x][searchY] !== null) {
+ var candy = grid[x][searchY];
+ grid[x][y] = candy;
+ grid[x][searchY] = null;
+ candy.gridY = y;
+ var targetY = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
+ candy.animateToPosition(candy.x, targetY, 300);
+ needsGravity = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ // Spawn new candies
+ for (var x = 0; x < GRID_SIZE; x++) {
+ for (var y = 0; y < GRID_SIZE; y++) {
+ if (grid[x][y] === null) {
+ var candyType = Math.floor(Math.random() * CANDY_TYPES);
+ var candy = new Candy(candyType);
+ candy.setGridPosition(x, y);
+ candy.y = GRID_START_Y - CELL_SIZE;
+ var targetY = GRID_START_Y + y * CELL_SIZE + CELL_SIZE / 2;
+ candy.animateToPosition(candy.x, targetY, 400);
+ grid[x][y] = candy;
+ game.addChild(candy);
+ needsGravity = true;
+ }
+ }
+ }
+ if (needsGravity) {
+ LK.setTimeout(function () {
+ checkForMatches();
+ }, 500);
+ } else {
+ isProcessing = false;
+ }
+}
+function checkForMatches() {
+ var matches = findAllMatches();
+ if (matches.length > 0) {
+ removeMatches(matches);
+ } else {
+ isProcessing = false;
+ }
+}
+function isAdjacent(candy1, candy2) {
+ var dx = Math.abs(candy1.gridX - candy2.gridX);
+ var dy = Math.abs(candy1.gridY - candy2.gridY);
+ return dx === 1 && dy === 0 || dx === 0 && dy === 1;
+}
+function getCandyAtPosition(x, y) {
+ for (var gx = 0; gx < GRID_SIZE; gx++) {
+ for (var gy = 0; gy < GRID_SIZE; gy++) {
+ var candy = grid[gx][gy];
+ if (candy && !candy.isMatched) {
+ var candyBounds = {
+ x: candy.x - CELL_SIZE / 2,
+ y: candy.y - CELL_SIZE / 2,
+ width: CELL_SIZE,
+ height: CELL_SIZE
+ };
+ if (x >= candyBounds.x && x <= candyBounds.x + candyBounds.width && y >= candyBounds.y && y <= candyBounds.y + candyBounds.height) {
+ return candy;
+ }
+ }
+ }
+ }
+ return null;
+}
+// Game event handlers
+game.down = function (x, y, obj) {
+ if (isProcessing) return;
+ var candy = getCandyAtPosition(x, y);
+ if (candy) {
+ if (selectedCandy) {
+ selectedCandy.alpha = 1.0;
+ }
+ selectedCandy = candy;
+ candy.alpha = 0.7;
+ }
+};
+game.up = function (x, y, obj) {
+ if (isProcessing || !selectedCandy) return;
+ var targetCandy = getCandyAtPosition(x, y);
+ if (targetCandy && targetCandy !== selectedCandy && isAdjacent(selectedCandy, targetCandy)) {
+ isProcessing = true;
+ // Try the swap
+ var candy1 = selectedCandy;
+ var candy2 = targetCandy;
+ if (swapCandies(candy1, candy2)) {
+ LK.getSound('swap').play();
+ // Animate the swap
+ var targetX1 = candy1.x;
+ var targetY1 = candy1.y;
+ var targetX2 = candy2.x;
+ var targetY2 = candy2.y;
+ candy1.animateToPosition(targetX1, targetY1, 200);
+ candy2.animateToPosition(targetX2, targetY2, 200, function () {
+ // Check for matches after swap
+ var matches1 = findMatches(candy1.gridX, candy1.gridY);
+ var matches2 = findMatches(candy2.gridX, candy2.gridY);
+ var allSwapMatches = matches1.concat(matches2);
+ // Remove duplicates
+ var uniqueMatches = [];
+ for (var i = 0; i < allSwapMatches.length; i++) {
+ var found = false;
+ for (var j = 0; j < uniqueMatches.length; j++) {
+ if (allSwapMatches[i] === uniqueMatches[j]) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ uniqueMatches.push(allSwapMatches[i]);
+ }
+ }
+ if (uniqueMatches.length > 0) {
+ moves--;
+ movesText.setText('Moves: ' + moves);
+ removeMatches(uniqueMatches);
+ } else {
+ // Invalid move, swap back
+ swapCandies(candy1, candy2);
+ candy1.animateToPosition(targetX2, targetY2, 200);
+ candy2.animateToPosition(targetX1, targetY1, 200, function () {
+ isProcessing = false;
+ });
+ }
+ });
+ } else {
+ isProcessing = false;
+ }
+ }
+ if (selectedCandy) {
+ selectedCandy.alpha = 1.0;
+ selectedCandy = null;
+ }
+};
+// Game update loop
+game.update = function () {
+ // Check win condition
+ if (score >= targetScore) {
+ LK.showYouWin();
+ }
+ // Check lose condition
+ if (moves <= 0 && score < targetScore) {
+ LK.showGameOver();
+ }
+};
+// Initialize the game
+initializeGrid();
\ No newline at end of file