/****
* 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"];
var candySymbols = {
"candy1": "♥",
"candy2": "★",
"candy3": "●",
"candy4": "▲",
"candy5": "♦",
"candy6": "♣"
};
if (!candyType) {
do {
candyType = candyTypes[Math.floor(Math.random() * candyTypes.length)];
} while (isPotentialMatch(i, j, candyType));
}
self.candyType = candyType;
var candyGraphics = self.attachAsset(candyType, {
anchorX: 0.5,
anchorY: 0.5
});
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;
// Oluşma animasyonu hızlandırıldı (400ms -> 250ms)
self.scale.x = 0;
self.scale.y = 0;
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 250,
easing: tween.easeOutBack
});
self.select = function () {
tween(self.scale, {
x: 1.2,
y: 1.2
}, {
duration: 100,
easing: tween.easeOutQuad
});
self.zIndex = 10;
};
self.deselect = function () {
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 100,
easing: tween.easeOutQuad
});
self.zIndex = 0;
};
self.destroyCandy = function () {
tween(self.scale, {
x: 0,
y: 0
}, {
duration: 150,
// Yok olma hızı artırıldı
easing: tween.easeInBack,
onComplete: function onComplete() {
self.destroy();
}
});
};
self.transformToWhite = function () {
self.removeChild(candyGraphics);
var whiteType = self.candyType + "_white";
candyGraphics = self.attachAsset(whiteType, {
anchorX: 0.5,
anchorY: 0.5
});
self.removeChild(symbolText);
self.addChild(symbolText);
symbolText.fill = 0x000000;
};
self.moveTo = function (newI, newJ, _onComplete) {
self.isMoving = true;
var oldJ = self.j;
self.i = newI;
self.j = newJ;
var isFalling = newJ > oldJ && newI === self.i;
// Düşme ve kayma hızları CİDDİ ORANDA artırıldı
// Double kill hissi için şekerin hemen düşmesi lazım
var animDuration = isFalling ? 300 : 200;
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
});
/****
* Game Code
****/
/**** * Game Code
****/
var score = 0;
var scoreMultiplier = 1;
var comboChain = 0; // Seri yakalama sayacı
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);
tween(scoreTxt.scale, {
x: 1.2,
y: 1.2
}, {
duration: 100,
yoyo: true,
onComplete: function onComplete() {
scoreTxt.scale.set(1, 1);
}
});
}
function playComboSound() {
comboChain++;
var soundId = 'sfx_1';
if (comboChain === 2) {
soundId = 'sfx_2';
} else if (comboChain === 3) {
soundId = 'sfx_3';
} else if (comboChain === 4) {
soundId = 'sfx_4';
} else if (comboChain >= 5) {
soundId = 'sfx_5';
}
// Sesin çalındığından emin olmak için basit bir kontrol
if (LK.getSound(soundId)) {
LK.getSound(soundId).play();
}
}
var board = [];
var boardSize = 8;
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 (candy1 === candy2) {
candy1.deselect();
}
return;
}
candy1.deselect();
isProcessing = true;
LK.getSound('swap').play();
// Yeni hamlede seri sıfırlanır
comboChain = 0;
var tempI1 = candy1.i;
var tempJ1 = candy1.j;
var tempI2 = candy2.i;
var tempJ2 = candy2.j;
board[tempI1][tempJ1] = candy2;
board[tempI2][tempJ2] = candy1;
candy1.moveTo(tempI2, tempJ2);
candy2.moveTo(tempI1, tempJ1);
// Swap animasyonunu beklerken süreyi kısalttık (300 -> 200)
LK.setTimeout(function () {
var matchInfo1 = checkAndDestroyMatches(candy1);
var matchInfo2 = checkAndDestroyMatches(candy2);
if (!matchInfo1.hasMatch && !matchInfo2.hasMatch) {
board[tempI1][tempJ1] = candy1;
board[tempI2][tempJ2] = candy2;
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;
}, 250);
} else {
// İLK PATLATMA (First Blood)
playComboSound();
if (matchInfo1.hasMatch) {
handleMatchVisuals(candy1, matchInfo1);
}
if (matchInfo2.hasMatch) {
handleMatchVisuals(candy2, matchInfo2);
}
// Hemen ardından zinciri kontrol et (300 -> 250)
LK.setTimeout(function () {
processMatches();
}, 250);
}
}, 250);
}
function handleMatchVisuals(candy, matchInfo) {
if (matchInfo.isFourMatch) {
candy.transformToWhite();
} else {
board[candy.i][candy.j] = null;
candy.destroyCandy();
}
}
function checkAndDestroyMatches(candy) {
var hasMatch = false;
var isFourMatch = false;
var candiesToDestroy = [];
var i = candy.i;
var j = candy.j;
var matchedCandies = [candy];
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;
}));
}
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;
}));
}
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();
// Bekleme süresi KRİTİK. 700ms çok uzundu.
// Şekerlerin düşme süresi (300ms) + çok az bir pay (50ms) yeterli.
LK.setTimeout(function () {
if (checkAllMatches()) {
// ARDARDA PATLATMA (Double, Triple, vs.)
playComboSound();
// Bir sonraki kontrol için bekleme süresi
LK.setTimeout(function () {
processMatches();
}, 350);
} else {
isProcessing = false;
scoreMultiplier = 1;
}
}, 350);
}
function checkAllMatches() {
var foundMatch = false;
var uniqueToDestroy = [];
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) {
if (uniqueToDestroy.indexOf(c) === -1) {
uniqueToDestroy.push(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) {
if (uniqueToDestroy.indexOf(c) === -1) {
uniqueToDestroy.push(c);
}
});
}
}
}
}
if (foundMatch) {
uniqueToDestroy.forEach(function (c) {
if (board[c.i][c.j]) {
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);
// Şekerler ekranın biraz daha yukarısından hızlıca düşsün
newCandy.x = i * candySize + candySize / 2 + marginX;
newCandy.y = -candySize * (emptySpaces - j) * 1.2 + 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 {
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 () {}; /****
* 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"];
var candySymbols = {
"candy1": "♥",
"candy2": "★",
"candy3": "●",
"candy4": "▲",
"candy5": "♦",
"candy6": "♣"
};
if (!candyType) {
do {
candyType = candyTypes[Math.floor(Math.random() * candyTypes.length)];
} while (isPotentialMatch(i, j, candyType));
}
self.candyType = candyType;
var candyGraphics = self.attachAsset(candyType, {
anchorX: 0.5,
anchorY: 0.5
});
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;
// Oluşma animasyonu hızlandırıldı (400ms -> 250ms)
self.scale.x = 0;
self.scale.y = 0;
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 250,
easing: tween.easeOutBack
});
self.select = function () {
tween(self.scale, {
x: 1.2,
y: 1.2
}, {
duration: 100,
easing: tween.easeOutQuad
});
self.zIndex = 10;
};
self.deselect = function () {
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 100,
easing: tween.easeOutQuad
});
self.zIndex = 0;
};
self.destroyCandy = function () {
tween(self.scale, {
x: 0,
y: 0
}, {
duration: 150,
// Yok olma hızı artırıldı
easing: tween.easeInBack,
onComplete: function onComplete() {
self.destroy();
}
});
};
self.transformToWhite = function () {
self.removeChild(candyGraphics);
var whiteType = self.candyType + "_white";
candyGraphics = self.attachAsset(whiteType, {
anchorX: 0.5,
anchorY: 0.5
});
self.removeChild(symbolText);
self.addChild(symbolText);
symbolText.fill = 0x000000;
};
self.moveTo = function (newI, newJ, _onComplete) {
self.isMoving = true;
var oldJ = self.j;
self.i = newI;
self.j = newJ;
var isFalling = newJ > oldJ && newI === self.i;
// Düşme ve kayma hızları CİDDİ ORANDA artırıldı
// Double kill hissi için şekerin hemen düşmesi lazım
var animDuration = isFalling ? 300 : 200;
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
});
/****
* Game Code
****/
/**** * Game Code
****/
var score = 0;
var scoreMultiplier = 1;
var comboChain = 0; // Seri yakalama sayacı
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);
tween(scoreTxt.scale, {
x: 1.2,
y: 1.2
}, {
duration: 100,
yoyo: true,
onComplete: function onComplete() {
scoreTxt.scale.set(1, 1);
}
});
}
function playComboSound() {
comboChain++;
var soundId = 'sfx_1';
if (comboChain === 2) {
soundId = 'sfx_2';
} else if (comboChain === 3) {
soundId = 'sfx_3';
} else if (comboChain === 4) {
soundId = 'sfx_4';
} else if (comboChain >= 5) {
soundId = 'sfx_5';
}
// Sesin çalındığından emin olmak için basit bir kontrol
if (LK.getSound(soundId)) {
LK.getSound(soundId).play();
}
}
var board = [];
var boardSize = 8;
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 (candy1 === candy2) {
candy1.deselect();
}
return;
}
candy1.deselect();
isProcessing = true;
LK.getSound('swap').play();
// Yeni hamlede seri sıfırlanır
comboChain = 0;
var tempI1 = candy1.i;
var tempJ1 = candy1.j;
var tempI2 = candy2.i;
var tempJ2 = candy2.j;
board[tempI1][tempJ1] = candy2;
board[tempI2][tempJ2] = candy1;
candy1.moveTo(tempI2, tempJ2);
candy2.moveTo(tempI1, tempJ1);
// Swap animasyonunu beklerken süreyi kısalttık (300 -> 200)
LK.setTimeout(function () {
var matchInfo1 = checkAndDestroyMatches(candy1);
var matchInfo2 = checkAndDestroyMatches(candy2);
if (!matchInfo1.hasMatch && !matchInfo2.hasMatch) {
board[tempI1][tempJ1] = candy1;
board[tempI2][tempJ2] = candy2;
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;
}, 250);
} else {
// İLK PATLATMA (First Blood)
playComboSound();
if (matchInfo1.hasMatch) {
handleMatchVisuals(candy1, matchInfo1);
}
if (matchInfo2.hasMatch) {
handleMatchVisuals(candy2, matchInfo2);
}
// Hemen ardından zinciri kontrol et (300 -> 250)
LK.setTimeout(function () {
processMatches();
}, 250);
}
}, 250);
}
function handleMatchVisuals(candy, matchInfo) {
if (matchInfo.isFourMatch) {
candy.transformToWhite();
} else {
board[candy.i][candy.j] = null;
candy.destroyCandy();
}
}
function checkAndDestroyMatches(candy) {
var hasMatch = false;
var isFourMatch = false;
var candiesToDestroy = [];
var i = candy.i;
var j = candy.j;
var matchedCandies = [candy];
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;
}));
}
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;
}));
}
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();
// Bekleme süresi KRİTİK. 700ms çok uzundu.
// Şekerlerin düşme süresi (300ms) + çok az bir pay (50ms) yeterli.
LK.setTimeout(function () {
if (checkAllMatches()) {
// ARDARDA PATLATMA (Double, Triple, vs.)
playComboSound();
// Bir sonraki kontrol için bekleme süresi
LK.setTimeout(function () {
processMatches();
}, 350);
} else {
isProcessing = false;
scoreMultiplier = 1;
}
}, 350);
}
function checkAllMatches() {
var foundMatch = false;
var uniqueToDestroy = [];
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) {
if (uniqueToDestroy.indexOf(c) === -1) {
uniqueToDestroy.push(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) {
if (uniqueToDestroy.indexOf(c) === -1) {
uniqueToDestroy.push(c);
}
});
}
}
}
}
if (foundMatch) {
uniqueToDestroy.forEach(function (c) {
if (board[c.i][c.j]) {
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);
// Şekerler ekranın biraz daha yukarısından hızlıca düşsün
newCandy.x = i * candySize + candySize / 2 + marginX;
newCandy.y = -candySize * (emptySpaces - j) * 1.2 + 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 {
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 () {};