Code edit (9 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Entegre bir AI (örneğin Cursor, GitHub Copilot veya IDE içi asistanlar) kodu zaten "görebildiği" ve bağlama hakim olduğu için, prompt'u kopyala-yapıştır mantığından çıkarıp doğrudan yerinde düzenleme (refactoring) talimatlarına dönüştürmemiz gerekir. Bu durumda prompt, kodu tanıtmak yerine nelerin değişmesi gerektiğine odaklanmalıdır. İşte entegre AI sistemleri için optimize edilmiş prompt: 📋 Entegre AI İçin Prompt Context: You are an expert Game Developer working on the currently open JavaScript file which uses the LK (Lumi/Loom) framework. Objective: Refactor the existing code to implement "Juiciness" (Game Feel), Audio, and Visual improvements without breaking the core logic. Tasks: Visual Overhaul (Square & Unique Designs): Modify the Candy class. Instead of simple colored boxes, create unique "Square" designs. Inside the Candy constructor, generate a unique geometric shape (e.g., a smaller inner square, a cross, or a circle) inside the main container based on the candyType. This ensures the squares are distinguishable by shape, not just color. Use LK.init.shape or standard drawing methods to achieve this procedurally. Animation Polish (Easing): Locate the moveTo and refillBoard functions. Update the tween configurations. Change the easing from linear (default) to something more dynamic: Use Back.Out (or a similar bounce effect) for candies falling/refilling to give them weight. Use Cubic.InOut for the swapCandies animation to make it feel responsive. Slightly adjust the animation duration (e.g., 200ms-300ms) for a snappier feel. Audio Integration: Introduce a sound management logic. Trigger LK.getSound('match').play() (or appropriate method) inside checkAndDestroyMatches when a match occurs. Trigger LK.getSound('swap').play() inside swapCandies. Add a specific sound for "4-match" combos if possible. Action: Directly apply these changes to the code. Ensure all new logic is integrated into the existing Candy class and main game loop functions correctly. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (4 edits merged)
Please save this source code
User prompt
hamle kalmadıktan sonra oyunun bitmesi için hamle yapamaya çalışmak gerekiyor şuan. bunun yerine son hamle yapıldıktan sonra eğer düşecek şeker varsa düşmeler gerçekleşir ve oyun sona erer
User prompt
her yer değiştirme işleminden sonra tüm şekerlerin düşmesi beklensin ve muhtemel eşleşmeler kontrol edilsin böylece şekerler havada kalmışken oyun bitmez
User prompt
her yer değiştirme işleminden sonra muhtemel eşleşmeler kontrol edilsin böylece şekerler havada kalmışken oyun bitmez
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'i')' in or related to this line: 'var i = candy.i;' Line Number: 241
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
/**** * Classes
****/
var Candy = Container.expand(function (i, j, candyType) {
var self = Container.call(this);
var candyTypes = ["candy1", "candy2", "candy3", "candy4", "candy5", "candy6"];
// Mapping colors to unique symbols for distinct visuals
var candySymbols = {
"candy1": "♥",
// Heart
"candy2": "★",
// Star
"candy3": "●",
// Circle
"candy4": "▲",
// Triangle
"candy5": "♦",
// Diamond
"candy6": "♣" // Club
};
if (!candyType) {
do {
candyType = candyTypes[Math.floor(Math.random() * candyTypes.length)];
} while (isPotentialMatch(i, j, candyType));
}
self.candyType = candyType;
// Background Shape
var candyGraphics = self.attachAsset(candyType, {
anchorX: 0.5,
anchorY: 0.5
});
// Unique Symbol Overlay
var symbolText = new Text2(candySymbols[candyType], {
size: 80,
fill: 0xffffff,
dropShadow: true,
dropShadowDistance: 2,
dropShadowColor: 0x000000,
dropShadowAlpha: 0.5
});
symbolText.anchor.set(0.5, 0.5);
self.addChild(symbolText);
self.i = i;
self.j = j;
self.isMoving = false;
// Animation: Scale up from 0 when created (Pop in effect)
self.scale.x = 0;
self.scale.y = 0;
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 400,
easing: tween.easeOutBack
});
self.select = function () {
// Pulse animation when selected
tween(self.scale, {
x: 1.2,
y: 1.2
}, {
duration: 150,
easing: tween.easeOutQuad
});
self.zIndex = 10; // Bring to front
};
self.deselect = function () {
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 150,
easing: tween.easeOutQuad
});
self.zIndex = 0;
};
self.destroyCandy = function () {
// Animation: Shrink before destroying
tween(self.scale, {
x: 0,
y: 0
}, {
duration: 200,
easing: tween.easeInBack,
onComplete: function onComplete() {
self.destroy();
}
});
};
self.transformToWhite = function () {
self.removeChild(candyGraphics);
// Keep the symbol but change background
var whiteType = self.candyType + "_white";
candyGraphics = self.attachAsset(whiteType, {
anchorX: 0.5,
anchorY: 0.5
});
// Re-add symbol on top
self.removeChild(symbolText);
self.addChild(symbolText);
symbolText.fill = 0x000000; // Switch text to black for white candy
};
self.moveTo = function (newI, newJ, _onComplete) {
self.isMoving = true;
var oldJ = self.j;
self.i = newI;
self.j = newJ;
// Determine animation type based on movement (Falling vs Swapping)
var isFalling = newJ > oldJ && newI === self.i;
var animDuration = isFalling ? 600 : 250;
var animEasing = isFalling ? tween.easeOutBounce : tween.easeInOutQuad;
tween(self, {
x: newI * candySize + candySize / 2 + marginX,
y: newJ * candySize + candySize / 2 + marginY
}, {
duration: animDuration,
easing: animEasing,
onComplete: function onComplete() {
self.isMoving = false;
if (_onComplete) {
_onComplete();
}
}
});
};
return self;
});
/****
* Initialize Game
****/
/**** * Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a // Slightly lighter background for contrast
});
/****
* Game Code
****/
/**** * Plugins
****/
// Softer Cyan
// Softer Magenta
// Softer Yellow
// Softer Blue
// Softer Green
// Softer Red
// We keep the shapes but we will overlay symbols in the Class to make them unique
/**** * Game Code
****/
var score = 0;
var scoreMultiplier = 1;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
function updateScore(points) {
score += points * scoreMultiplier;
scoreTxt.setText('Score: ' + score);
// Tiny score bump animation
var originalScale = scoreTxt.scale.x; // Assuming x and y are same
tween(scoreTxt.scale, {
x: 1.2,
y: 1.2
}, {
duration: 100,
yoyo: true,
onComplete: function onComplete() {
scoreTxt.scale.set(1, 1);
}
});
}
var board = [];
var boardSize = 8; // Reduced slightly for bigger candies
var candySize = Math.min(2048, 2732) / (boardSize + 0.5);
var selectedCandy = null;
var marginY = (2732 - boardSize * candySize) / 2;
var marginX = (2048 - boardSize * candySize) / 2;
var isProcessing = false;
function isPotentialMatch(i, j, candyType) {
if (i >= 2 && board[i - 1][j] && board[i - 2][j] && board[i - 1][j].candyType === candyType && board[i - 2][j].candyType === candyType) {
return true;
}
if (j >= 2 && board[i][j - 1] && board[i][j - 2] && board[i][j - 1].candyType === candyType && board[i][j - 2].candyType === candyType) {
return true;
}
return false;
}
function initializeBoard() {
for (var i = 0; i < boardSize; i++) {
board[i] = [];
for (var j = 0; j < boardSize; j++) {
var candy = new Candy(i, j);
candy.x = i * candySize + candySize / 2 + marginX;
candy.y = j * candySize + candySize / 2 + marginY;
board[i][j] = candy;
game.addChild(candy);
}
}
}
function swapCandies(candy1, candy2) {
if (!candy1 || !candy2 || isProcessing) {
return;
}
var dx = Math.abs(candy1.i - candy2.i);
var dy = Math.abs(candy1.j - candy2.j);
if (dx === 1 && dy === 1 || dx === 0 && dy === 0) {
// If clicking same candy or diagonal, just deselect
if (candy1 === candy2) candy1.deselect();
return;
}
candy1.deselect(); // Remove selection effect
isProcessing = true;
LK.getSound('swap').play();
var tempI1 = candy1.i;
var tempJ1 = candy1.j;
var tempI2 = candy2.i;
var tempJ2 = candy2.j;
// Logic swap
board[tempI1][tempJ1] = candy2;
board[tempI2][tempJ2] = candy1;
// Visual swap
candy1.moveTo(tempI2, tempJ2);
candy2.moveTo(tempI1, tempJ1);
LK.setTimeout(function () {
var matchInfo1 = checkAndDestroyMatches(candy1);
var matchInfo2 = checkAndDestroyMatches(candy2);
if (!matchInfo1.hasMatch && !matchInfo2.hasMatch) {
// Revert Logic
board[tempI1][tempJ1] = candy1;
board[tempI2][tempJ2] = candy2;
// Revert Visual
candy1.moveTo(tempI1, tempJ1);
candy2.moveTo(tempI2, tempJ2);
candy1.i = tempI1;
candy1.j = tempJ1;
candy2.i = tempI2;
candy2.j = tempJ2;
LK.setTimeout(function () {
isProcessing = false;
}, 300);
} else {
// Handle matches
if (matchInfo1.hasMatch) handleMatchVisuals(candy1, matchInfo1);
if (matchInfo2.hasMatch) handleMatchVisuals(candy2, matchInfo2);
LK.setTimeout(function () {
processMatches();
}, 300);
}
}, 300);
}
function handleMatchVisuals(candy, matchInfo) {
if (matchInfo.isFourMatch) {
candy.transformToWhite();
LK.getSound('combo').play();
} else {
board[candy.i][candy.j] = null;
candy.destroyCandy();
LK.getSound('match').play();
}
}
function checkAndDestroyMatches(candy) {
var hasMatch = false;
var isFourMatch = false;
var candiesToDestroy = [];
var i = candy.i;
var j = candy.j;
var matchedCandies = [candy];
// Horizontal
var left = i - 1;
while (left >= 0 && board[left][j] && board[left][j].candyType === candy.candyType) {
matchedCandies.push(board[left][j]);
left--;
}
var right = i + 1;
while (right < boardSize && board[right][j] && board[right][j].candyType === candy.candyType) {
matchedCandies.push(board[right][j]);
right++;
}
if (matchedCandies.length >= 3) {
hasMatch = true;
if (matchedCandies.length >= 4) isFourMatch = true;
candiesToDestroy = candiesToDestroy.concat(matchedCandies.filter(function (c) {
return c !== candy;
}));
}
// Vertical
matchedCandies = [candy];
var up = j - 1;
while (up >= 0 && board[i][up] && board[i][up].candyType === candy.candyType) {
matchedCandies.push(board[i][up]);
up--;
}
var down = j + 1;
while (down < boardSize && board[i][down] && board[i][down].candyType === candy.candyType) {
matchedCandies.push(board[i][down]);
down++;
}
if (matchedCandies.length >= 3) {
hasMatch = true;
if (matchedCandies.length >= 4) isFourMatch = true;
candiesToDestroy = candiesToDestroy.concat(matchedCandies.filter(function (c) {
return c !== candy;
}));
}
// Destroy logic
candiesToDestroy.forEach(function (c) {
board[c.i][c.j] = null;
c.destroyCandy();
});
if (hasMatch) {
updateScore(isFourMatch ? 100 : 50);
scoreMultiplier++;
} else {
scoreMultiplier = 1;
}
return {
hasMatch: hasMatch,
isFourMatch: isFourMatch
};
}
function processMatches() {
refillBoard();
LK.setTimeout(function () {
if (checkAllMatches()) {
LK.setTimeout(function () {
processMatches();
}, 600); // Increased delay for visual clarity
} else {
isProcessing = false;
scoreMultiplier = 1;
}
}, 700);
}
function checkAllMatches() {
var foundMatch = false;
// Helper to add unique candies to destroy list
var uniqueToDestroy = new Set();
for (var i = 0; i < boardSize; i++) {
for (var j = 0; j < boardSize; j++) {
if (board[i][j]) {
var candy = board[i][j];
// Horizontal
var hMatches = [candy];
var k = 1;
while (i + k < boardSize && board[i + k][j] && board[i + k][j].candyType === candy.candyType) {
hMatches.push(board[i + k][j]);
k++;
}
if (hMatches.length >= 3) {
foundMatch = true;
hMatches.forEach(function (c) {
return uniqueToDestroy.add(c);
});
}
// Vertical
var vMatches = [candy];
k = 1;
while (j + k < boardSize && board[i][j + k] && board[i][j + k].candyType === candy.candyType) {
vMatches.push(board[i][j + k]);
k++;
}
if (vMatches.length >= 3) {
foundMatch = true;
vMatches.forEach(function (c) {
return uniqueToDestroy.add(c);
});
}
}
}
}
if (foundMatch) {
LK.getSound('match').play();
uniqueToDestroy.forEach(function (c) {
if (board[c.i][c.j]) {
// Check if still valid
board[c.i][c.j] = null;
c.destroyCandy();
updateScore(10);
}
});
}
return foundMatch;
}
function refillBoard() {
for (var i = 0; i < boardSize; i++) {
var emptySpaces = 0;
for (var j = boardSize - 1; j >= 0; j--) {
if (!board[i][j]) {
emptySpaces++;
} else if (emptySpaces > 0) {
board[i][j + emptySpaces] = board[i][j];
board[i][j + emptySpaces].moveTo(i, j + emptySpaces);
board[i][j] = null;
}
}
for (var j = emptySpaces - 1; j >= 0; j--) {
var newCandy = new Candy(i, j);
// Start higher up for a nice "drop" effect
newCandy.x = i * candySize + candySize / 2 + marginX;
newCandy.y = -candySize * (emptySpaces - j) * 1.5 + marginY;
board[i][j] = newCandy;
game.addChild(newCandy);
newCandy.moveTo(i, j);
}
}
}
game.down = function (x, y) {
if (isProcessing) {
return;
}
var i = Math.floor((x - marginX) / candySize);
var j = Math.floor((y - marginY) / candySize);
if (i >= 0 && i < boardSize && j >= 0 && j < boardSize) {
var clickedCandy = board[i][j];
if (!clickedCandy) return;
if (selectedCandy) {
var dx = Math.abs(selectedCandy.i - i);
var dy = Math.abs(selectedCandy.j - j);
if (dx === 1 && dy === 0 || dx === 0 && dy === 1) {
swapCandies(selectedCandy, clickedCandy);
selectedCandy = null;
} else {
// Clicked far away? Select the new one instead
selectedCandy.deselect();
selectedCandy = clickedCandy;
selectedCandy.select();
}
} else {
selectedCandy = clickedCandy;
selectedCandy.select();
}
}
};
initializeBoard();
var resetButton = LK.getAsset('resetButton', {
anchorX: 1,
anchorY: 1,
x: 2048 - 50,
y: 2732 - 50
});
LK.gui.bottomRight.addChild(resetButton);
resetButton.down = function () {
LK.showGameOver();
};
game.update = function () {}; ===================================================================
--- original.js
+++ change.js
@@ -5,46 +5,125 @@
/****
* Classes
****/
+/**** * Classes
+****/
var Candy = Container.expand(function (i, j, candyType) {
var self = Container.call(this);
var candyTypes = ["candy1", "candy2", "candy3", "candy4", "candy5", "candy6"];
+ // Mapping colors to unique symbols for distinct visuals
+ var candySymbols = {
+ "candy1": "♥",
+ // Heart
+ "candy2": "★",
+ // Star
+ "candy3": "●",
+ // Circle
+ "candy4": "▲",
+ // Triangle
+ "candy5": "♦",
+ // Diamond
+ "candy6": "♣" // Club
+ };
if (!candyType) {
do {
candyType = candyTypes[Math.floor(Math.random() * candyTypes.length)];
} while (isPotentialMatch(i, j, candyType));
}
self.candyType = candyType;
+ // Background Shape
var candyGraphics = self.attachAsset(candyType, {
anchorX: 0.5,
anchorY: 0.5
});
+ // Unique Symbol Overlay
+ var symbolText = new Text2(candySymbols[candyType], {
+ size: 80,
+ fill: 0xffffff,
+ dropShadow: true,
+ dropShadowDistance: 2,
+ dropShadowColor: 0x000000,
+ dropShadowAlpha: 0.5
+ });
+ symbolText.anchor.set(0.5, 0.5);
+ self.addChild(symbolText);
self.i = i;
self.j = j;
self.isMoving = false;
+ // Animation: Scale up from 0 when created (Pop in effect)
+ self.scale.x = 0;
+ self.scale.y = 0;
+ tween(self.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 400,
+ easing: tween.easeOutBack
+ });
+ self.select = function () {
+ // Pulse animation when selected
+ tween(self.scale, {
+ x: 1.2,
+ y: 1.2
+ }, {
+ duration: 150,
+ easing: tween.easeOutQuad
+ });
+ self.zIndex = 10; // Bring to front
+ };
+ self.deselect = function () {
+ tween(self.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 150,
+ easing: tween.easeOutQuad
+ });
+ self.zIndex = 0;
+ };
self.destroyCandy = function () {
- self.destroy();
+ // Animation: Shrink before destroying
+ tween(self.scale, {
+ x: 0,
+ y: 0
+ }, {
+ duration: 200,
+ easing: tween.easeInBack,
+ onComplete: function onComplete() {
+ self.destroy();
+ }
+ });
};
self.transformToWhite = function () {
self.removeChild(candyGraphics);
- self.candyType = self.candyType + "_white";
- candyGraphics = self.attachAsset(self.candyType, {
+ // Keep the symbol but change background
+ var whiteType = self.candyType + "_white";
+ candyGraphics = self.attachAsset(whiteType, {
anchorX: 0.5,
anchorY: 0.5
});
+ // Re-add symbol on top
+ self.removeChild(symbolText);
+ self.addChild(symbolText);
+ symbolText.fill = 0x000000; // Switch text to black for white candy
};
self.moveTo = function (newI, newJ, _onComplete) {
self.isMoving = true;
+ var oldJ = self.j;
self.i = newI;
self.j = newJ;
+ // Determine animation type based on movement (Falling vs Swapping)
+ var isFalling = newJ > oldJ && newI === self.i;
+ var animDuration = isFalling ? 600 : 250;
+ var animEasing = isFalling ? tween.easeOutBounce : tween.easeInOutQuad;
tween(self, {
x: newI * candySize + candySize / 2 + marginX,
y: newJ * candySize + candySize / 2 + marginY
}, {
- duration: 300,
- easing: tween.bounceOut,
- onFinish: function onFinish() {
+ duration: animDuration,
+ easing: animEasing,
+ onComplete: function onComplete() {
self.isMoving = false;
if (_onComplete) {
_onComplete();
}
@@ -56,36 +135,60 @@
/****
* Initialize Game
****/
+/**** * Initialize Game
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x1a1a1a // Slightly lighter background for contrast
});
/****
* Game Code
****/
+/**** * Plugins
+****/
+// Softer Cyan
+// Softer Magenta
+// Softer Yellow
+// Softer Blue
+// Softer Green
+// Softer Red
+// We keep the shapes but we will overlay symbols in the Class to make them unique
+/**** * Game Code
+****/
var score = 0;
var scoreMultiplier = 1;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
-scoreTxt.anchor.set(1, 0); // Anchor to the top-right corner
+scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
function updateScore(points) {
score += points * scoreMultiplier;
scoreTxt.setText('Score: ' + score);
+ // Tiny score bump animation
+ var originalScale = scoreTxt.scale.x; // Assuming x and y are same
+ tween(scoreTxt.scale, {
+ x: 1.2,
+ y: 1.2
+ }, {
+ duration: 100,
+ yoyo: true,
+ onComplete: function onComplete() {
+ scoreTxt.scale.set(1, 1);
+ }
+ });
}
var board = [];
-var boardSize = 9;
+var boardSize = 8; // Reduced slightly for bigger candies
var candySize = Math.min(2048, 2732) / (boardSize + 0.5);
var selectedCandy = null;
var marginY = (2732 - boardSize * candySize) / 2;
var marginX = (2048 - boardSize * candySize) / 2;
var isProcessing = false;
function isPotentialMatch(i, j, candyType) {
- // Oyun başlangıcında 3'lü eşleşmeleri engelliyoruz
if (i >= 2 && board[i - 1][j] && board[i - 2][j] && board[i - 1][j].candyType === candyType && board[i - 2][j].candyType === candyType) {
return true;
}
if (j >= 2 && board[i][j - 1] && board[i][j - 2] && board[i][j - 1].candyType === candyType && board[i][j - 2].candyType === candyType) {
@@ -111,84 +214,70 @@
}
var dx = Math.abs(candy1.i - candy2.i);
var dy = Math.abs(candy1.j - candy2.j);
if (dx === 1 && dy === 1 || dx === 0 && dy === 0) {
- return; // Çapraz veya aynı yere tıklamayı engelle
+ // If clicking same candy or diagonal, just deselect
+ if (candy1 === candy2) candy1.deselect();
+ return;
}
+ candy1.deselect(); // Remove selection effect
isProcessing = true;
LK.getSound('swap').play();
var tempI1 = candy1.i;
var tempJ1 = candy1.j;
var tempI2 = candy2.i;
var tempJ2 = candy2.j;
- // Tahtada yerlerini değiştir
+ // Logic swap
board[tempI1][tempJ1] = candy2;
board[tempI2][tempJ2] = candy1;
- // Görsel olarak yerlerini değiştir
- tween(candy1, {
- x: tempI2 * candySize + candySize / 2 + marginX,
- y: tempJ2 * candySize + candySize / 2 + marginY
- }, {
- duration: 250,
- easing: tween.cubicInOut
- });
- tween(candy2, {
- x: tempI1 * candySize + candySize / 2 + marginX,
- y: tempJ1 * candySize + candySize / 2 + marginY
- }, {
- duration: 250,
- easing: tween.cubicInOut
- });
+ // Visual swap
+ candy1.moveTo(tempI2, tempJ2);
+ candy2.moveTo(tempI1, tempJ1);
LK.setTimeout(function () {
- // Yer değiştiren her iki şekeri de kontrol et
var matchInfo1 = checkAndDestroyMatches(candy1);
var matchInfo2 = checkAndDestroyMatches(candy2);
- // Eşleşme yoksa geri döndür
if (!matchInfo1.hasMatch && !matchInfo2.hasMatch) {
+ // Revert Logic
board[tempI1][tempJ1] = candy1;
board[tempI2][tempJ2] = candy2;
+ // Revert Visual
candy1.moveTo(tempI1, tempJ1);
candy2.moveTo(tempI2, tempJ2);
candy1.i = tempI1;
candy1.j = tempJ1;
candy2.i = tempI2;
candy2.j = tempJ2;
LK.setTimeout(function () {
isProcessing = false;
- }, 500);
+ }, 300);
} else {
- if (matchInfo1.hasMatch) {
- // candy1 eşleşme sağladı
- if (matchInfo1.isFourMatch) {
- candy1.transformToWhite();
- } else {
- board[candy1.i][candy1.j] = null;
- candy1.destroyCandy();
- }
- }
- if (matchInfo2.hasMatch) {
- // candy2 eşleşme sağladı
- if (matchInfo2.isFourMatch) {
- candy2.transformToWhite();
- } else {
- board[candy2.i][candy2.j] = null;
- candy2.destroyCandy();
- }
- }
+ // Handle matches
+ if (matchInfo1.hasMatch) handleMatchVisuals(candy1, matchInfo1);
+ if (matchInfo2.hasMatch) handleMatchVisuals(candy2, matchInfo2);
LK.setTimeout(function () {
processMatches();
}, 300);
}
- }, 600);
+ }, 300);
}
+function handleMatchVisuals(candy, matchInfo) {
+ if (matchInfo.isFourMatch) {
+ candy.transformToWhite();
+ LK.getSound('combo').play();
+ } else {
+ board[candy.i][candy.j] = null;
+ candy.destroyCandy();
+ LK.getSound('match').play();
+ }
+}
function checkAndDestroyMatches(candy) {
var hasMatch = false;
var isFourMatch = false;
var candiesToDestroy = [];
var i = candy.i;
var j = candy.j;
var matchedCandies = [candy];
- // Yatay kontrol
+ // Horizontal
var left = i - 1;
while (left >= 0 && board[left][j] && board[left][j].candyType === candy.candyType) {
matchedCandies.push(board[left][j]);
left--;
@@ -199,16 +288,14 @@
right++;
}
if (matchedCandies.length >= 3) {
hasMatch = true;
- if (matchedCandies.length === 4) {
- isFourMatch = true;
- }
+ if (matchedCandies.length >= 4) isFourMatch = true;
candiesToDestroy = candiesToDestroy.concat(matchedCandies.filter(function (c) {
return c !== candy;
}));
}
- // Dikey kontrol
+ // Vertical
matchedCandies = [candy];
var up = j - 1;
while (up >= 0 && board[i][up] && board[i][up].candyType === candy.candyType) {
matchedCandies.push(board[i][up]);
@@ -220,31 +307,23 @@
down++;
}
if (matchedCandies.length >= 3) {
hasMatch = true;
- if (matchedCandies.length === 4) {
- isFourMatch = true;
- }
+ if (matchedCandies.length >= 4) isFourMatch = true;
candiesToDestroy = candiesToDestroy.concat(matchedCandies.filter(function (c) {
return c !== candy;
}));
}
- // Eşleşen şekerleri yok et
+ // Destroy logic
candiesToDestroy.forEach(function (c) {
board[c.i][c.j] = null;
c.destroyCandy();
});
if (hasMatch) {
- LK.getSound('match').play();
- if (isFourMatch) {
- updateScore(100); // 4-match score
- LK.getSound('combo').play();
- } else {
- updateScore(50); // 3-match score
- }
+ updateScore(isFourMatch ? 100 : 50);
scoreMultiplier++;
} else {
- scoreMultiplier = 1; // Reset multiplier if no match
+ scoreMultiplier = 1;
}
return {
hasMatch: hasMatch,
isFourMatch: isFourMatch
@@ -255,77 +334,63 @@
LK.setTimeout(function () {
if (checkAllMatches()) {
LK.setTimeout(function () {
processMatches();
- }, 300);
+ }, 600); // Increased delay for visual clarity
} else {
isProcessing = false;
- scoreMultiplier = 1; // Reset multiplier after processing
+ scoreMultiplier = 1;
}
- }, 600);
+ }, 700);
}
function checkAllMatches() {
var foundMatch = false;
+ // Helper to add unique candies to destroy list
+ var uniqueToDestroy = new Set();
for (var i = 0; i < boardSize; i++) {
for (var j = 0; j < boardSize; j++) {
if (board[i][j]) {
var candy = board[i][j];
- var candiesToDestroy = [];
- var matchedCandies = [candy];
- // Yatay kontrol
- var left = i - 1;
- while (left >= 0 && board[left][j] && board[left][j].candyType === candy.candyType) {
- matchedCandies.push(board[left][j]);
- left--;
+ // Horizontal
+ var hMatches = [candy];
+ var k = 1;
+ while (i + k < boardSize && board[i + k][j] && board[i + k][j].candyType === candy.candyType) {
+ hMatches.push(board[i + k][j]);
+ k++;
}
- var right = i + 1;
- while (right < boardSize && board[right][j] && board[right][j].candyType === candy.candyType) {
- matchedCandies.push(board[right][j]);
- right++;
- }
- if (matchedCandies.length >= 3) {
+ if (hMatches.length >= 3) {
foundMatch = true;
- candiesToDestroy = candiesToDestroy.concat(matchedCandies);
- if (candiesToDestroy.length === 4) {
- updateScore(100); // 4-match score
- } else if (candiesToDestroy.length >= 3) {
- updateScore(50); // 3-match score
- }
- } else {
- // Dikey kontrol
- matchedCandies = [candy];
- var up = j - 1;
- while (up >= 0 && board[i][up] && board[i][up].candyType === candy.candyType) {
- matchedCandies.push(board[i][up]);
- up--;
- }
- var down = j + 1;
- while (down < boardSize && board[i][down] && board[i][down].candyType === candy.candyType) {
- matchedCandies.push(board[i][down]);
- down++;
- }
- if (matchedCandies.length >= 3) {
- foundMatch = true;
- candiesToDestroy = candiesToDestroy.concat(matchedCandies);
- }
+ hMatches.forEach(function (c) {
+ return uniqueToDestroy.add(c);
+ });
}
- // Eşleşen şekerleri yok et
- if (candiesToDestroy.length >= 3) {
- if (candiesToDestroy.length === 4) {
- updateScore(100); // 4-match score
- } else if (candiesToDestroy.length >= 3) {
- updateScore(50); // 3-match score
- }
- candiesToDestroy.forEach(function (c) {
- if (board[c.i][c.j]) {
- board[c.i][c.j] = null;
- c.destroyCandy();
- }
+ // Vertical
+ var vMatches = [candy];
+ k = 1;
+ while (j + k < boardSize && board[i][j + k] && board[i][j + k].candyType === candy.candyType) {
+ vMatches.push(board[i][j + k]);
+ k++;
+ }
+ if (vMatches.length >= 3) {
+ foundMatch = true;
+ vMatches.forEach(function (c) {
+ return uniqueToDestroy.add(c);
});
}
}
}
}
+ if (foundMatch) {
+ LK.getSound('match').play();
+ uniqueToDestroy.forEach(function (c) {
+ if (board[c.i][c.j]) {
+ // Check if still valid
+ board[c.i][c.j] = null;
+ c.destroyCandy();
+ updateScore(10);
+ }
+ });
+ }
return foundMatch;
}
function refillBoard() {
for (var i = 0; i < boardSize; i++) {
@@ -340,10 +405,11 @@
}
}
for (var j = emptySpaces - 1; j >= 0; j--) {
var newCandy = new Candy(i, j);
+ // Start higher up for a nice "drop" effect
newCandy.x = i * candySize + candySize / 2 + marginX;
- newCandy.y = -candySize * (emptySpaces - j) + candySize / 2 + marginY;
+ newCandy.y = -candySize * (emptySpaces - j) * 1.5 + marginY;
board[i][j] = newCandy;
game.addChild(newCandy);
newCandy.moveTo(i, j);
}
@@ -355,30 +421,36 @@
}
var i = Math.floor((x - marginX) / candySize);
var j = Math.floor((y - marginY) / candySize);
if (i >= 0 && i < boardSize && j >= 0 && j < boardSize) {
+ var clickedCandy = board[i][j];
+ if (!clickedCandy) return;
if (selectedCandy) {
var dx = Math.abs(selectedCandy.i - i);
var dy = Math.abs(selectedCandy.j - j);
if (dx === 1 && dy === 0 || dx === 0 && dy === 1) {
- swapCandies(selectedCandy, board[i][j]);
+ swapCandies(selectedCandy, clickedCandy);
+ selectedCandy = null;
+ } else {
+ // Clicked far away? Select the new one instead
+ selectedCandy.deselect();
+ selectedCandy = clickedCandy;
+ selectedCandy.select();
}
- selectedCandy = null;
} else {
- selectedCandy = board[i][j];
+ selectedCandy = clickedCandy;
+ selectedCandy.select();
}
}
};
initializeBoard();
var resetButton = LK.getAsset('resetButton', {
anchorX: 1,
anchorY: 1,
x: 2048 - 50,
- // Positioning the button at the bottom-right corner
y: 2732 - 50
});
LK.gui.bottomRight.addChild(resetButton);
resetButton.down = function () {
- LK.showGameOver(); // This will reset the game state
+ LK.showGameOver();
};
-game.update = function () {};
-;
\ No newline at end of file
+game.update = function () {};
\ No newline at end of file