User prompt
fix music bacground
User prompt
perbaiki teknis score
User prompt
buat batas waktu 150 detik
User prompt
gambar background perbaiki agar tajam
User prompt
add background asset
Code edit (1 edits merged)
Please save this source code
User prompt
Memory Master
Initial prompt
permainan memoy ingatan
/**** * 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; // 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('Moves: 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('Moves: ' + moves); // 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++; // Check if game is won if (matchedPairs === totalPairs) { LK.clearInterval(gameTimer); LK.setTimeout(function () { LK.setScore(Math.max(1000 - moves * 10, 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); // 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 };
===================================================================
--- original.js
+++ change.js
@@ -79,9 +79,9 @@
}
});
};
self.down = function (x, y, obj) {
- if (gameState === 'playing' && !self.isFlipped && !self.isMatched) {
+ if (gameState === 'playing' && !self.isFlipped && !self.isMatched && timeLeft > 0) {
handleCardClick(self);
}
};
return self;
@@ -102,8 +102,10 @@
var flippedCards = [];
var moves = 0;
var matchedPairs = 0;
var totalPairs = 8;
+var timeLeft = 150;
+var gameTimer;
// Grid configuration
var gridCols = 4;
var gridRows = 4;
var cardSpacing = 220;
@@ -115,8 +117,16 @@
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) {
@@ -168,8 +178,9 @@
card2.setMatched();
matchedPairs++;
// Check if game is won
if (matchedPairs === totalPairs) {
+ LK.clearInterval(gameTimer);
LK.setTimeout(function () {
LK.setScore(Math.max(1000 - moves * 10, 100));
LK.showYouWin();
}, 500);
@@ -188,8 +199,18 @@
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);
// Initialize the game
initializeBoard();
// Game update loop
game.update = function () {
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