/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Card = Container.expand(function (cardType) {
var self = Container.call(this);
self.cardType = cardType;
self.isFlipped = false;
self.isMatched = false;
var cardBack = self.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5
});
var cardFront = self.attachAsset('cardFront' + cardType, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
self.flip = function () {
if (self.isFlipped || self.isMatched) return;
self.isFlipped = true;
LK.getSound('flip').play();
// Flip animation
tween(cardBack, {
scaleX: 0
}, {
duration: 150,
onFinish: function onFinish() {
cardBack.alpha = 0;
cardFront.alpha = 1;
cardFront.scaleX = 0;
tween(cardFront, {
scaleX: 1
}, {
duration: 150
});
}
});
};
self.flipBack = function () {
if (!self.isFlipped || self.isMatched) return;
self.isFlipped = false;
// Flip back animation
tween(cardFront, {
scaleX: 0
}, {
duration: 150,
onFinish: function onFinish() {
cardFront.alpha = 0;
cardBack.alpha = 1;
cardBack.scaleX = 0;
tween(cardBack, {
scaleX: 1
}, {
duration: 150
});
}
});
};
self.setMatched = function () {
self.isMatched = true;
// Slight scale animation to show match
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
self.down = function (x, y, obj) {
if (gameState === 'playing' && !self.isFlipped && !self.isMatched && timeLeft > 0) {
handleCardClick(self);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
var gameState = 'playing';
var cards = [];
var flippedCards = [];
var moves = 0;
var matchedPairs = 0;
var totalPairs = 8;
var timeLeft = 150;
var gameTimer;
var currentScore = 0;
// Grid configuration
var gridCols = 4;
var gridRows = 4;
var cardSpacing = 220;
var startX = (2048 - (gridCols - 1) * cardSpacing) / 2;
var startY = (2732 - (gridRows - 1) * cardSpacing) / 2;
// Create score display
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create timer display
var timerText = new Text2('Time: 150', {
size: 80,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
timerText.y = 100;
LK.gui.top.addChild(timerText);
// Create card types array (2 of each type for pairs)
var cardTypes = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8];
// Shuffle function
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
// Initialize game board
function initializeBoard() {
shuffleArray(cardTypes);
for (var row = 0; row < gridRows; row++) {
for (var col = 0; col < gridCols; col++) {
var index = row * gridCols + col;
var card = new Card(cardTypes[index]);
card.x = startX + col * cardSpacing;
card.y = startY + row * cardSpacing;
cards.push(card);
game.addChild(card);
}
}
}
// Handle card click
function handleCardClick(card) {
if (flippedCards.length >= 2) return;
card.flip();
flippedCards.push(card);
if (flippedCards.length === 2) {
moves++;
scoreText.setText('Score: ' + currentScore);
// Check for match after a short delay
LK.setTimeout(function () {
checkForMatch();
}, 1000);
}
}
// Check if flipped cards match
function checkForMatch() {
if (flippedCards.length !== 2) return;
var card1 = flippedCards[0];
var card2 = flippedCards[1];
if (card1.cardType === card2.cardType) {
// Match found
LK.getSound('match').play();
card1.setMatched();
card2.setMatched();
matchedPairs++;
// Award points for match
currentScore += 100;
scoreText.setText('Score: ' + currentScore);
// Check if game is won
if (matchedPairs === totalPairs) {
LK.clearInterval(gameTimer);
LK.setTimeout(function () {
// Calculate final score with time bonus
var timeBonus = timeLeft * 5;
var finalScore = currentScore + timeBonus - moves * 5;
LK.setScore(Math.max(finalScore, 100));
LK.showYouWin();
}, 500);
}
} else {
// No match
LK.getSound('noMatch').play();
card1.flipBack();
card2.flipBack();
}
flippedCards = [];
}
// Add background
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Start the timer
gameTimer = LK.setInterval(function () {
timeLeft--;
timerText.setText('Time: ' + timeLeft);
if (timeLeft <= 0) {
LK.clearInterval(gameTimer);
gameState = 'gameOver';
LK.showGameOver();
}
}, 1000);
// Start background music
LK.playMusic('1lovelake');
// Initialize the game
initializeBoard();
// Game update loop
game.update = function () {
// Game logic is handled by events and timers
// No continuous updates needed for this game
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Card = Container.expand(function (cardType) {
var self = Container.call(this);
self.cardType = cardType;
self.isFlipped = false;
self.isMatched = false;
var cardBack = self.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5
});
var cardFront = self.attachAsset('cardFront' + cardType, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
self.flip = function () {
if (self.isFlipped || self.isMatched) return;
self.isFlipped = true;
LK.getSound('flip').play();
// Flip animation
tween(cardBack, {
scaleX: 0
}, {
duration: 150,
onFinish: function onFinish() {
cardBack.alpha = 0;
cardFront.alpha = 1;
cardFront.scaleX = 0;
tween(cardFront, {
scaleX: 1
}, {
duration: 150
});
}
});
};
self.flipBack = function () {
if (!self.isFlipped || self.isMatched) return;
self.isFlipped = false;
// Flip back animation
tween(cardFront, {
scaleX: 0
}, {
duration: 150,
onFinish: function onFinish() {
cardFront.alpha = 0;
cardBack.alpha = 1;
cardBack.scaleX = 0;
tween(cardBack, {
scaleX: 1
}, {
duration: 150
});
}
});
};
self.setMatched = function () {
self.isMatched = true;
// Slight scale animation to show match
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
self.down = function (x, y, obj) {
if (gameState === 'playing' && !self.isFlipped && !self.isMatched && timeLeft > 0) {
handleCardClick(self);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
var gameState = 'playing';
var cards = [];
var flippedCards = [];
var moves = 0;
var matchedPairs = 0;
var totalPairs = 8;
var timeLeft = 150;
var gameTimer;
var currentScore = 0;
// Grid configuration
var gridCols = 4;
var gridRows = 4;
var cardSpacing = 220;
var startX = (2048 - (gridCols - 1) * cardSpacing) / 2;
var startY = (2732 - (gridRows - 1) * cardSpacing) / 2;
// Create score display
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create timer display
var timerText = new Text2('Time: 150', {
size: 80,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
timerText.y = 100;
LK.gui.top.addChild(timerText);
// Create card types array (2 of each type for pairs)
var cardTypes = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8];
// Shuffle function
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
// Initialize game board
function initializeBoard() {
shuffleArray(cardTypes);
for (var row = 0; row < gridRows; row++) {
for (var col = 0; col < gridCols; col++) {
var index = row * gridCols + col;
var card = new Card(cardTypes[index]);
card.x = startX + col * cardSpacing;
card.y = startY + row * cardSpacing;
cards.push(card);
game.addChild(card);
}
}
}
// Handle card click
function handleCardClick(card) {
if (flippedCards.length >= 2) return;
card.flip();
flippedCards.push(card);
if (flippedCards.length === 2) {
moves++;
scoreText.setText('Score: ' + currentScore);
// Check for match after a short delay
LK.setTimeout(function () {
checkForMatch();
}, 1000);
}
}
// Check if flipped cards match
function checkForMatch() {
if (flippedCards.length !== 2) return;
var card1 = flippedCards[0];
var card2 = flippedCards[1];
if (card1.cardType === card2.cardType) {
// Match found
LK.getSound('match').play();
card1.setMatched();
card2.setMatched();
matchedPairs++;
// Award points for match
currentScore += 100;
scoreText.setText('Score: ' + currentScore);
// Check if game is won
if (matchedPairs === totalPairs) {
LK.clearInterval(gameTimer);
LK.setTimeout(function () {
// Calculate final score with time bonus
var timeBonus = timeLeft * 5;
var finalScore = currentScore + timeBonus - moves * 5;
LK.setScore(Math.max(finalScore, 100));
LK.showYouWin();
}, 500);
}
} else {
// No match
LK.getSound('noMatch').play();
card1.flipBack();
card2.flipBack();
}
flippedCards = [];
}
// Add background
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Start the timer
gameTimer = LK.setInterval(function () {
timeLeft--;
timerText.setText('Time: ' + timeLeft);
if (timeLeft <= 0) {
LK.clearInterval(gameTimer);
gameState = 'gameOver';
LK.showGameOver();
}
}, 1000);
// Start background music
LK.playMusic('1lovelake');
// Initialize the game
initializeBoard();
// Game update loop
game.update = function () {
// Game logic is handled by events and timers
// No continuous updates needed for this game
};
gambar gaya anime capung dengan background sungai. In-Game asset. 2d. High contrast. No shadows
gambar anime ulat caterpilar di batang pohon. In-Game asset. 2d. High contrast. No shadows
gambar 2d anime burung hantu dalam lubang pohon. In-Game asset. 2d. High contrast. No shadows
gambar 2d anime cicada hinggap di batang besar lebar pohon. In-Game asset. 2d. High contrast. No shadows
gambar 2d anime belalang hijau menempel di rumput panjang. In-Game asset. 2d. High contrast. No shadows
gambar 2d anime kodok hijau di atas batu hitam dalam hutan. In-Game asset. 2d. High contrast. No shadows
gambar 2d anime kelinci hare menunggu dalam lubang tanah di bawah pohon dalam hutan. In-Game asset. 2d. High contrast. No shadows
gambar 2d anime sifut slug di atas permukaan hutan. In-Game asset. 2d. High contrast. No shadows