/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var MainMenu = Container.expand(function () { var self = Container.call(this); self.titleText = new Text2('Animal Match', { size: 80, fill: 0xFFFFFF }); self.titleText.anchor.set(0.5, 0.5); self.titleText.x = 1024; self.titleText.y = 800; self.addChild(self.titleText); self.startButton = self.attachAsset('startButton', { anchorX: 0.5, anchorY: 0.5 }); self.startButton.x = 1024; self.startButton.y = 1200; self.startButtonText = new Text2('START GAME', { size: 50, fill: 0xFFFFFF }); self.startButtonText.anchor.set(0.5, 0.5); self.startButtonText.x = 1024; self.startButtonText.y = 1200; self.addChild(self.startButtonText); // Add decorative animals around the menu self.animal1 = self.attachAsset('cardFront1', { anchorX: 0.5, anchorY: 0.5 }); self.animal1.x = 400; self.animal1.y = 600; self.animal1.scaleX = 1.2; self.animal1.scaleY = 1.2; self.animal2 = self.attachAsset('cardFront2', { anchorX: 0.5, anchorY: 0.5 }); self.animal2.x = 1648; self.animal2.y = 600; self.animal2.scaleX = 1.2; self.animal2.scaleY = 1.2; self.animal3 = self.attachAsset('cardFront3', { anchorX: 0.5, anchorY: 0.5 }); self.animal3.x = 300; self.animal3.y = 1000; self.animal3.scaleX = 1.1; self.animal3.scaleY = 1.1; self.animal4 = self.attachAsset('cardFront4', { anchorX: 0.5, anchorY: 0.5 }); self.animal4.x = 1748; self.animal4.y = 1000; self.animal4.scaleX = 1.1; self.animal4.scaleY = 1.1; self.animal5 = self.attachAsset('cardFront5', { anchorX: 0.5, anchorY: 0.5 }); self.animal5.x = 512; self.animal5.y = 1400; self.animal5.scaleX = 0.9; self.animal5.scaleY = 0.9; self.animal6 = self.attachAsset('cardFront6', { anchorX: 0.5, anchorY: 0.5 }); self.animal6.x = 1536; self.animal6.y = 1400; self.animal6.scaleX = 0.9; self.animal6.scaleY = 0.9; // Only the start button should start the game, not the decorative animals self.startButton.down = function (x, y, obj) { startGame(); }; return self; }); var MatchingCard = Container.expand(function (cardType, row, col) { var self = Container.call(this); self.cardType = cardType; self.row = row; self.col = col; self.isFlipped = false; self.isMatched = false; self.canClick = true; self.cardBack = self.attachAsset('cardBack', { anchorX: 0.5, anchorY: 0.5 }); self.cardFront = self.attachAsset('cardFront' + cardType, { anchorX: 0.5, anchorY: 0.5 }); self.cardFront.visible = false; self.flip = function () { if (!self.canClick || self.isMatched) return; self.isFlipped = !self.isFlipped; self.cardBack.visible = !self.isFlipped; self.cardFront.visible = self.isFlipped; LK.getSound('cardFlip').play(); }; self.setMatched = function () { self.isMatched = true; self.canClick = false; self.removeChild(self.cardBack); self.removeChild(self.cardFront); self.matchedGraphics = self.attachAsset('cardMatched', { anchorX: 0.5, anchorY: 0.5 }); }; self.flipBack = function () { if (self.isMatched) return; self.isFlipped = false; self.cardBack.visible = true; self.cardFront.visible = false; }; self.down = function (x, y, obj) { if (!self.canClick || self.isMatched) return; handleCardClick(self); }; return self; }); var NextLevelButton = Container.expand(function () { var self = Container.call(this); self.buttonGraphics = self.attachAsset('nextLevelButton', { anchorX: 0.5, anchorY: 0.5 }); self.buttonText = new Text2('Next Level', { size: 40, fill: 0xFFFFFF }); self.buttonText.anchor.set(0.5, 0.5); self.addChild(self.buttonText); self.visible = false; self.show = function () { self.visible = true; tween(self, { alpha: 1 }, { duration: 300 }); }; self.hide = function () { self.visible = false; self.alpha = 0; }; self.down = function (x, y, obj) { nextLevel(); }; return self; }); var VictoryScreen = Container.expand(function () { var self = Container.call(this); // Add full screen background self.background = self.attachAsset('victoryBackground', { anchorX: 0, anchorY: 0 }); self.background.x = 0; self.background.y = 0; self.titleText = new Text2('Congratulations!', { size: 80, fill: 0xFFD700 }); self.titleText.anchor.set(0.5, 0.5); self.titleText.x = 1024; self.titleText.y = 800; self.addChild(self.titleText); self.subtitleText = new Text2('You completed all levels!', { size: 50, fill: 0xFFFFFF }); self.subtitleText.anchor.set(0.5, 0.5); self.subtitleText.x = 1024; self.subtitleText.y = 920; self.addChild(self.subtitleText); // Add decorative animals around the victory screen with new assets self.animal1 = self.attachAsset('victoryAnimal1', { anchorX: 0.5, anchorY: 0.5 }); self.animal1.x = 400; self.animal1.y = 600; self.animal1.scaleX = 1.5; self.animal1.scaleY = 1.5; self.animal2 = self.attachAsset('victoryAnimal2', { anchorX: 0.5, anchorY: 0.5 }); self.animal2.x = 1648; self.animal2.y = 600; self.animal2.scaleX = 1.5; self.animal2.scaleY = 1.5; self.animal3 = self.attachAsset('victoryAnimal3', { anchorX: 0.5, anchorY: 0.5 }); self.animal3.x = 300; self.animal3.y = 1100; self.animal3.scaleX = 1.3; self.animal3.scaleY = 1.3; self.animal4 = self.attachAsset('victoryAnimal4', { anchorX: 0.5, anchorY: 0.5 }); self.animal4.x = 1748; self.animal4.y = 1100; self.animal4.scaleX = 1.3; self.animal4.scaleY = 1.3; self.animal5 = self.attachAsset('victoryAnimal5', { anchorX: 0.5, anchorY: 0.5 }); self.animal5.x = 512; self.animal5.y = 1300; self.animal5.scaleX = 1.0; self.animal5.scaleY = 1.0; self.animal6 = self.attachAsset('victoryAnimal6', { anchorX: 0.5, anchorY: 0.5 }); self.animal6.x = 1536; self.animal6.y = 1300; self.animal6.scaleX = 1.0; self.animal6.scaleY = 1.0; self.animal7 = self.attachAsset('victoryAnimal7', { anchorX: 0.5, anchorY: 0.5 }); self.animal7.x = 200; self.animal7.y = 1500; self.animal7.scaleX = 0.8; self.animal7.scaleY = 0.8; self.animal8 = self.attachAsset('victoryAnimal8', { anchorX: 0.5, anchorY: 0.5 }); self.animal8.x = 1848; self.animal8.y = 1500; self.animal8.scaleX = 0.8; self.animal8.scaleY = 0.8; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var gameStarted = false; var mainMenu = null; var currentLevel = 1; storage.currentLevel = 1; var maxLevel = storage.maxLevel || 1; var cardGrid = []; var flippedCards = []; var matchedPairs = 0; var totalPairs = 0; var levelComplete = false; var gridSize = 4; var cellSpacing = 180; var waitingForFlipBack = false; var levelText = new Text2('Level 1', { size: 60, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); levelText.y = 100; levelText.visible = false; var instructionText = new Text2('Find matching pairs of cards\nFlip two cards to match them!', { size: 40, fill: 0xECF0F1 }); instructionText.anchor.set(0.5, 0.5); game.addChild(instructionText); instructionText.x = 1024; instructionText.y = 600; instructionText.visible = false; var nextButton = game.addChild(new NextLevelButton()); nextButton.x = 1024; nextButton.y = 2200; nextButton.visible = false; function startGame() { gameStarted = true; if (mainMenu) { mainMenu.destroy(); mainMenu = null; } levelText.visible = true; instructionText.visible = true; nextButton.visible = true; createMatchingGame(); } function createMatchingGame() { cardGrid = []; flippedCards = []; matchedPairs = 0; levelComplete = false; waitingForFlipBack = false; // Determine grid size based on level if (currentLevel <= 3) { gridSize = 4; // 4x4 = 16 cards = 8 pairs } else if (currentLevel <= 6) { gridSize = 5; // 5x4 = 20 cards = 10 pairs (we'll use 5x4 grid) } else { gridSize = 6; // 6x4 = 24 cards = 12 pairs } var actualCols = gridSize === 5 ? 4 : 4; var actualRows = gridSize === 5 ? 5 : gridSize === 6 ? 6 : 4; totalPairs = actualRows * actualCols / 2; // Create pairs array var cardTypes = []; var maxCardType = Math.min(8, totalPairs); for (var i = 1; i <= maxCardType; i++) { cardTypes.push(i); cardTypes.push(i); } // Fill remaining slots if needed while (cardTypes.length < totalPairs * 2) { var randomType = Math.floor(Math.random() * maxCardType) + 1; cardTypes.push(randomType); cardTypes.push(randomType); } // Shuffle the array for (var i = cardTypes.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = cardTypes[i]; cardTypes[i] = cardTypes[j]; cardTypes[j] = temp; } var startX = 1024 - (actualCols - 1) * cellSpacing / 2; var startY = 1366 - (actualRows - 1) * cellSpacing / 2; var cardIndex = 0; for (var row = 0; row < actualRows; row++) { cardGrid[row] = []; for (var col = 0; col < actualCols; col++) { var card = new MatchingCard(cardTypes[cardIndex], row, col); card.x = startX + col * cellSpacing; card.y = startY + row * cellSpacing; cardGrid[row][col] = card; game.addChild(card); cardIndex++; } } nextButton.hide(); } function handleCardClick(clickedCard) { if (waitingForFlipBack || clickedCard.isMatched || clickedCard.isFlipped) return; if (flippedCards.length >= 2) return; clickedCard.flip(); flippedCards.push(clickedCard); if (flippedCards.length === 2) { if (flippedCards[0].cardType === flippedCards[1].cardType) { // Match found! LK.getSound('matchFound').play(); // Add success animation - scale up both cards tween(flippedCards[0], { scaleX: 1.3, scaleY: 1.3 }, { duration: 200, easing: tween.easeOut }); tween(flippedCards[1], { scaleX: 1.3, scaleY: 1.3 }, { duration: 200, easing: tween.easeOut }); // Scale back and complete match LK.setTimeout(function () { tween(flippedCards[0], { scaleX: 1.0, scaleY: 1.0 }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { flippedCards[0].setMatched(); } }); tween(flippedCards[1], { scaleX: 1.0, scaleY: 1.0 }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { flippedCards[1].setMatched(); } }); }, 200); LK.setTimeout(function () { flippedCards = []; matchedPairs++; checkLevelComplete(); }, 600); } else { // No match, flip back after delay waitingForFlipBack = true; LK.setTimeout(function () { flippedCards[0].flipBack(); flippedCards[1].flipBack(); flippedCards = []; waitingForFlipBack = false; }, 1000); } } } function checkLevelComplete() { if (matchedPairs === totalPairs) { levelComplete = true; LK.getSound('levelComplete').play(); LK.effects.flashScreen(0x2ecc71, 500); if (currentLevel >= maxLevel) { maxLevel = currentLevel + 1; storage.maxLevel = maxLevel; } // Check if game is completed (level 5) if (currentLevel >= 5) { // Show victory screen instead of next level button LK.setTimeout(function () { // Hide all game elements levelText.visible = false; instructionText.visible = false; nextButton.visible = false; // Hide all cards for (var row = 0; row < cardGrid.length; row++) { for (var col = 0; col < cardGrid[row].length; col++) { if (cardGrid[row] && cardGrid[row][col]) { cardGrid[row][col].visible = false; } } } // Create and show victory screen var victoryScreen = game.addChild(new VictoryScreen()); victoryScreen.alpha = 0; tween(victoryScreen, { alpha: 1 }, { duration: 500 }); // Show celebration effect LK.effects.flashScreen(0xFFD700, 1000); LK.setTimeout(function () { LK.showYouWin(); }, 2000); }, 500); } else { nextButton.show(); LK.setTimeout(function () { tween(instructionText, { alpha: 0 }, { duration: 300 }); completedText = new Text2('Level Complete!', { size: 50, fill: 0x2ECC71 }); completedText.anchor.set(0.5, 0.5); completedText.x = 1024; completedText.y = 700; completedText.alpha = 0; game.addChild(completedText); tween(completedText, { alpha: 1 }, { duration: 500 }); }, 500); } } } var completedText = null; function nextLevel() { currentLevel++; storage.currentLevel = currentLevel; levelText.setText('Level ' + currentLevel); // Clean up existing cards for (var row = 0; row < cardGrid.length; row++) { for (var col = 0; col < cardGrid[row].length; col++) { if (cardGrid[row] && cardGrid[row][col]) { cardGrid[row][col].destroy(); } } } // Clean up completion text if (completedText) { completedText.destroy(); completedText = null; } createMatchingGame(); instructionText.alpha = 1; instructionText.setText('Find matching pairs of cards\nFlip two cards to match them!'); } function resetMatchingGame() { for (var row = 0; row < cardGrid.length; row++) { for (var col = 0; col < cardGrid[row].length; col++) { var card = cardGrid[row][col]; card.flipBack(); card.isMatched = false; card.canClick = true; } } flippedCards = []; matchedPairs = 0; levelComplete = false; waitingForFlipBack = false; nextButton.hide(); } function showMainMenu() { gameStarted = false; currentLevel = 1; storage.currentLevel = 1; levelText.setText('Level 1'); levelText.visible = false; instructionText.visible = false; nextButton.visible = false; // Clean up existing cards if any for (var row = 0; row < cardGrid.length; row++) { for (var col = 0; col < cardGrid[row].length; col++) { if (cardGrid[row] && cardGrid[row][col]) { cardGrid[row][col].destroy(); } } } cardGrid = []; // Clean up completion text if (completedText) { completedText.destroy(); completedText = null; } mainMenu = game.addChild(new MainMenu()); } showMainMenu(); game.update = function () { // Game loop updates handled by individual components };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var MainMenu = Container.expand(function () {
var self = Container.call(this);
self.titleText = new Text2('Animal Match', {
size: 80,
fill: 0xFFFFFF
});
self.titleText.anchor.set(0.5, 0.5);
self.titleText.x = 1024;
self.titleText.y = 800;
self.addChild(self.titleText);
self.startButton = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.startButton.x = 1024;
self.startButton.y = 1200;
self.startButtonText = new Text2('START GAME', {
size: 50,
fill: 0xFFFFFF
});
self.startButtonText.anchor.set(0.5, 0.5);
self.startButtonText.x = 1024;
self.startButtonText.y = 1200;
self.addChild(self.startButtonText);
// Add decorative animals around the menu
self.animal1 = self.attachAsset('cardFront1', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal1.x = 400;
self.animal1.y = 600;
self.animal1.scaleX = 1.2;
self.animal1.scaleY = 1.2;
self.animal2 = self.attachAsset('cardFront2', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal2.x = 1648;
self.animal2.y = 600;
self.animal2.scaleX = 1.2;
self.animal2.scaleY = 1.2;
self.animal3 = self.attachAsset('cardFront3', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal3.x = 300;
self.animal3.y = 1000;
self.animal3.scaleX = 1.1;
self.animal3.scaleY = 1.1;
self.animal4 = self.attachAsset('cardFront4', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal4.x = 1748;
self.animal4.y = 1000;
self.animal4.scaleX = 1.1;
self.animal4.scaleY = 1.1;
self.animal5 = self.attachAsset('cardFront5', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal5.x = 512;
self.animal5.y = 1400;
self.animal5.scaleX = 0.9;
self.animal5.scaleY = 0.9;
self.animal6 = self.attachAsset('cardFront6', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal6.x = 1536;
self.animal6.y = 1400;
self.animal6.scaleX = 0.9;
self.animal6.scaleY = 0.9;
// Only the start button should start the game, not the decorative animals
self.startButton.down = function (x, y, obj) {
startGame();
};
return self;
});
var MatchingCard = Container.expand(function (cardType, row, col) {
var self = Container.call(this);
self.cardType = cardType;
self.row = row;
self.col = col;
self.isFlipped = false;
self.isMatched = false;
self.canClick = true;
self.cardBack = self.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5
});
self.cardFront = self.attachAsset('cardFront' + cardType, {
anchorX: 0.5,
anchorY: 0.5
});
self.cardFront.visible = false;
self.flip = function () {
if (!self.canClick || self.isMatched) return;
self.isFlipped = !self.isFlipped;
self.cardBack.visible = !self.isFlipped;
self.cardFront.visible = self.isFlipped;
LK.getSound('cardFlip').play();
};
self.setMatched = function () {
self.isMatched = true;
self.canClick = false;
self.removeChild(self.cardBack);
self.removeChild(self.cardFront);
self.matchedGraphics = self.attachAsset('cardMatched', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.flipBack = function () {
if (self.isMatched) return;
self.isFlipped = false;
self.cardBack.visible = true;
self.cardFront.visible = false;
};
self.down = function (x, y, obj) {
if (!self.canClick || self.isMatched) return;
handleCardClick(self);
};
return self;
});
var NextLevelButton = Container.expand(function () {
var self = Container.call(this);
self.buttonGraphics = self.attachAsset('nextLevelButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonText = new Text2('Next Level', {
size: 40,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.visible = false;
self.show = function () {
self.visible = true;
tween(self, {
alpha: 1
}, {
duration: 300
});
};
self.hide = function () {
self.visible = false;
self.alpha = 0;
};
self.down = function (x, y, obj) {
nextLevel();
};
return self;
});
var VictoryScreen = Container.expand(function () {
var self = Container.call(this);
// Add full screen background
self.background = self.attachAsset('victoryBackground', {
anchorX: 0,
anchorY: 0
});
self.background.x = 0;
self.background.y = 0;
self.titleText = new Text2('Congratulations!', {
size: 80,
fill: 0xFFD700
});
self.titleText.anchor.set(0.5, 0.5);
self.titleText.x = 1024;
self.titleText.y = 800;
self.addChild(self.titleText);
self.subtitleText = new Text2('You completed all levels!', {
size: 50,
fill: 0xFFFFFF
});
self.subtitleText.anchor.set(0.5, 0.5);
self.subtitleText.x = 1024;
self.subtitleText.y = 920;
self.addChild(self.subtitleText);
// Add decorative animals around the victory screen with new assets
self.animal1 = self.attachAsset('victoryAnimal1', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal1.x = 400;
self.animal1.y = 600;
self.animal1.scaleX = 1.5;
self.animal1.scaleY = 1.5;
self.animal2 = self.attachAsset('victoryAnimal2', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal2.x = 1648;
self.animal2.y = 600;
self.animal2.scaleX = 1.5;
self.animal2.scaleY = 1.5;
self.animal3 = self.attachAsset('victoryAnimal3', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal3.x = 300;
self.animal3.y = 1100;
self.animal3.scaleX = 1.3;
self.animal3.scaleY = 1.3;
self.animal4 = self.attachAsset('victoryAnimal4', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal4.x = 1748;
self.animal4.y = 1100;
self.animal4.scaleX = 1.3;
self.animal4.scaleY = 1.3;
self.animal5 = self.attachAsset('victoryAnimal5', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal5.x = 512;
self.animal5.y = 1300;
self.animal5.scaleX = 1.0;
self.animal5.scaleY = 1.0;
self.animal6 = self.attachAsset('victoryAnimal6', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal6.x = 1536;
self.animal6.y = 1300;
self.animal6.scaleX = 1.0;
self.animal6.scaleY = 1.0;
self.animal7 = self.attachAsset('victoryAnimal7', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal7.x = 200;
self.animal7.y = 1500;
self.animal7.scaleX = 0.8;
self.animal7.scaleY = 0.8;
self.animal8 = self.attachAsset('victoryAnimal8', {
anchorX: 0.5,
anchorY: 0.5
});
self.animal8.x = 1848;
self.animal8.y = 1500;
self.animal8.scaleX = 0.8;
self.animal8.scaleY = 0.8;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var gameStarted = false;
var mainMenu = null;
var currentLevel = 1;
storage.currentLevel = 1;
var maxLevel = storage.maxLevel || 1;
var cardGrid = [];
var flippedCards = [];
var matchedPairs = 0;
var totalPairs = 0;
var levelComplete = false;
var gridSize = 4;
var cellSpacing = 180;
var waitingForFlipBack = false;
var levelText = new Text2('Level 1', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
levelText.y = 100;
levelText.visible = false;
var instructionText = new Text2('Find matching pairs of cards\nFlip two cards to match them!', {
size: 40,
fill: 0xECF0F1
});
instructionText.anchor.set(0.5, 0.5);
game.addChild(instructionText);
instructionText.x = 1024;
instructionText.y = 600;
instructionText.visible = false;
var nextButton = game.addChild(new NextLevelButton());
nextButton.x = 1024;
nextButton.y = 2200;
nextButton.visible = false;
function startGame() {
gameStarted = true;
if (mainMenu) {
mainMenu.destroy();
mainMenu = null;
}
levelText.visible = true;
instructionText.visible = true;
nextButton.visible = true;
createMatchingGame();
}
function createMatchingGame() {
cardGrid = [];
flippedCards = [];
matchedPairs = 0;
levelComplete = false;
waitingForFlipBack = false;
// Determine grid size based on level
if (currentLevel <= 3) {
gridSize = 4; // 4x4 = 16 cards = 8 pairs
} else if (currentLevel <= 6) {
gridSize = 5; // 5x4 = 20 cards = 10 pairs (we'll use 5x4 grid)
} else {
gridSize = 6; // 6x4 = 24 cards = 12 pairs
}
var actualCols = gridSize === 5 ? 4 : 4;
var actualRows = gridSize === 5 ? 5 : gridSize === 6 ? 6 : 4;
totalPairs = actualRows * actualCols / 2;
// Create pairs array
var cardTypes = [];
var maxCardType = Math.min(8, totalPairs);
for (var i = 1; i <= maxCardType; i++) {
cardTypes.push(i);
cardTypes.push(i);
}
// Fill remaining slots if needed
while (cardTypes.length < totalPairs * 2) {
var randomType = Math.floor(Math.random() * maxCardType) + 1;
cardTypes.push(randomType);
cardTypes.push(randomType);
}
// Shuffle the array
for (var i = cardTypes.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = cardTypes[i];
cardTypes[i] = cardTypes[j];
cardTypes[j] = temp;
}
var startX = 1024 - (actualCols - 1) * cellSpacing / 2;
var startY = 1366 - (actualRows - 1) * cellSpacing / 2;
var cardIndex = 0;
for (var row = 0; row < actualRows; row++) {
cardGrid[row] = [];
for (var col = 0; col < actualCols; col++) {
var card = new MatchingCard(cardTypes[cardIndex], row, col);
card.x = startX + col * cellSpacing;
card.y = startY + row * cellSpacing;
cardGrid[row][col] = card;
game.addChild(card);
cardIndex++;
}
}
nextButton.hide();
}
function handleCardClick(clickedCard) {
if (waitingForFlipBack || clickedCard.isMatched || clickedCard.isFlipped) return;
if (flippedCards.length >= 2) return;
clickedCard.flip();
flippedCards.push(clickedCard);
if (flippedCards.length === 2) {
if (flippedCards[0].cardType === flippedCards[1].cardType) {
// Match found!
LK.getSound('matchFound').play();
// Add success animation - scale up both cards
tween(flippedCards[0], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.easeOut
});
tween(flippedCards[1], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.easeOut
});
// Scale back and complete match
LK.setTimeout(function () {
tween(flippedCards[0], {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
flippedCards[0].setMatched();
}
});
tween(flippedCards[1], {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
flippedCards[1].setMatched();
}
});
}, 200);
LK.setTimeout(function () {
flippedCards = [];
matchedPairs++;
checkLevelComplete();
}, 600);
} else {
// No match, flip back after delay
waitingForFlipBack = true;
LK.setTimeout(function () {
flippedCards[0].flipBack();
flippedCards[1].flipBack();
flippedCards = [];
waitingForFlipBack = false;
}, 1000);
}
}
}
function checkLevelComplete() {
if (matchedPairs === totalPairs) {
levelComplete = true;
LK.getSound('levelComplete').play();
LK.effects.flashScreen(0x2ecc71, 500);
if (currentLevel >= maxLevel) {
maxLevel = currentLevel + 1;
storage.maxLevel = maxLevel;
}
// Check if game is completed (level 5)
if (currentLevel >= 5) {
// Show victory screen instead of next level button
LK.setTimeout(function () {
// Hide all game elements
levelText.visible = false;
instructionText.visible = false;
nextButton.visible = false;
// Hide all cards
for (var row = 0; row < cardGrid.length; row++) {
for (var col = 0; col < cardGrid[row].length; col++) {
if (cardGrid[row] && cardGrid[row][col]) {
cardGrid[row][col].visible = false;
}
}
}
// Create and show victory screen
var victoryScreen = game.addChild(new VictoryScreen());
victoryScreen.alpha = 0;
tween(victoryScreen, {
alpha: 1
}, {
duration: 500
});
// Show celebration effect
LK.effects.flashScreen(0xFFD700, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}, 500);
} else {
nextButton.show();
LK.setTimeout(function () {
tween(instructionText, {
alpha: 0
}, {
duration: 300
});
completedText = new Text2('Level Complete!', {
size: 50,
fill: 0x2ECC71
});
completedText.anchor.set(0.5, 0.5);
completedText.x = 1024;
completedText.y = 700;
completedText.alpha = 0;
game.addChild(completedText);
tween(completedText, {
alpha: 1
}, {
duration: 500
});
}, 500);
}
}
}
var completedText = null;
function nextLevel() {
currentLevel++;
storage.currentLevel = currentLevel;
levelText.setText('Level ' + currentLevel);
// Clean up existing cards
for (var row = 0; row < cardGrid.length; row++) {
for (var col = 0; col < cardGrid[row].length; col++) {
if (cardGrid[row] && cardGrid[row][col]) {
cardGrid[row][col].destroy();
}
}
}
// Clean up completion text
if (completedText) {
completedText.destroy();
completedText = null;
}
createMatchingGame();
instructionText.alpha = 1;
instructionText.setText('Find matching pairs of cards\nFlip two cards to match them!');
}
function resetMatchingGame() {
for (var row = 0; row < cardGrid.length; row++) {
for (var col = 0; col < cardGrid[row].length; col++) {
var card = cardGrid[row][col];
card.flipBack();
card.isMatched = false;
card.canClick = true;
}
}
flippedCards = [];
matchedPairs = 0;
levelComplete = false;
waitingForFlipBack = false;
nextButton.hide();
}
function showMainMenu() {
gameStarted = false;
currentLevel = 1;
storage.currentLevel = 1;
levelText.setText('Level 1');
levelText.visible = false;
instructionText.visible = false;
nextButton.visible = false;
// Clean up existing cards if any
for (var row = 0; row < cardGrid.length; row++) {
for (var col = 0; col < cardGrid[row].length; col++) {
if (cardGrid[row] && cardGrid[row][col]) {
cardGrid[row][col].destroy();
}
}
}
cardGrid = [];
// Clean up completion text
if (completedText) {
completedText.destroy();
completedText = null;
}
mainMenu = game.addChild(new MainMenu());
}
showMainMenu();
game.update = function () {
// Game loop updates handled by individual components
};
cat. In-Game asset. 2d. High contrast. No shadows
sheep with black background. In-Game asset. 2d. High contrast. No shadows
dog with black background. In-Game asset. 2d. High contrast. No shadows
horse with black background. In-Game asset. 2d. High contrast. No shadows
cow with black background. In-Game asset. 2d. High contrast. No shadows
siyah arkaplanlı bir horoz. In-Game asset. 2d. High contrast. No shadows
white chicken with black background. In-Game asset. 2d. High contrast. No shadows
pink pig with black background. In-Game asset. 2d. High contrast. No shadows
correct sign. In-Game asset. 2d. High contrast. No shadows
Patlamış havai fişek. In-Game asset. 2d. High contrast. No shadows