Code edit (2 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
add back and next buttons in the left and right bottom corners in the black color'
Code edit (4 edits merged)
Please save this source code
User prompt
display score in black color
User prompt
display time in the bottom of the page and top right corner dispaly score
Code edit (1 edits merged)
Please save this source code
User prompt
put just 5 levels for over all game
User prompt
add white color background
User prompt
add background asset in the game
User prompt
put animal pictures (images )instead of letters
User prompt
Please fix the bug: 'Timeout.tick error: timerText.setFill is not a function' in or related to this line: 'timerText.setFill("#ffffff");' Line Number: 319
User prompt
Please fix the bug: 'Timeout.tick error: timerText.setColor is not a function' in or related to this line: 'timerText.setColor("#ffffff");' Line Number: 314
Code edit (1 edits merged)
Please save this source code
User prompt
Flip & Match: Sound Safari
Initial prompt
2. Memory Match Game Concept: Flip cards to find matching pairs. Goal: Match all pairs within a time limit. Fun Twist: Each card plays a funny sound or animation when flipped.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0,
currentLevel: 1
});
/****
* Classes
****/
var Card = Container.expand(function (symbol, soundId) {
var self = Container.call(this);
self.symbol = symbol;
self.soundId = soundId;
self.isFlipped = false;
self.isMatched = false;
// Create card back (visible initially)
var back = self.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5
});
// Create card front (hidden initially)
var front = self.attachAsset('cardFront', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Add image to front
var image = self.attachAsset(symbol, {
anchorX: 0.5,
anchorY: 0.5
});
front.addChild(image);
// Make card interactive
self.interactive = true;
// Flip animation
self.flip = function () {
if (self.isMatched || self.isFlipped || !gameActive || flippedCards.length >= 2) {
return;
}
self.isFlipped = true;
LK.getSound('flip').play();
// Play the card's sound
if (self.soundId) {
LK.getSound(self.soundId).play();
}
// Animate card flip
tween(back, {
scaleX: 0
}, {
duration: 150,
onFinish: function onFinish() {
tween(front, {
alpha: 1
}, {
duration: 0
});
tween(front, {
scaleX: 1
}, {
duration: 150
});
}
});
// Add to flipped cards array
flippedCards.push(self);
// Check for match if two cards are flipped
if (flippedCards.length === 2) {
checkForMatch();
}
};
// Reset card to face down
self.reset = function () {
self.isFlipped = false;
tween(front, {
scaleX: 0
}, {
duration: 150,
onFinish: function onFinish() {
tween(front, {
alpha: 0
}, {
duration: 0
});
tween(back, {
scaleX: 1
}, {
duration: 150
});
}
});
};
// Show match animation
self.showMatch = function () {
self.isMatched = true;
// Pulse animation for matched cards
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
// Handle card press
self.down = function (x, y, obj) {
self.flip();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF
});
/****
* Game Code
****/
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Game variables
// Initialize animal images
var level = storage.currentLevel || 1;
var rows = 3;
var cols = 4;
var cardSpacing = 30;
var cardWidth = 300;
var cardHeight = 400;
var flippedCards = [];
var matchedPairs = 0;
var requiredPairs = 0;
var gameActive = false;
var timeLeft = 60;
var timeWarningGiven = false;
var gameTimer = null;
var cards = [];
var symbols = [];
var soundMap = {
'A': 'dog',
'B': 'cat',
'C': 'elephant',
'D': 'monkey',
'E': 'lion',
'F': 'bird',
'G': 'frog',
'H': 'dolphin'
};
// Difficulty settings based on level
function setDifficulty() {
if (level === 1) {
rows = 3;
cols = 4;
timeLeft = 60;
} else if (level === 2) {
rows = 4;
cols = 4;
timeLeft = 75;
} else {
rows = 4;
cols = 5;
timeLeft = 90;
}
requiredPairs = rows * cols / 2;
}
// Create symbols array
function createSymbols() {
var availableSymbols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
symbols = [];
// Create pairs of symbols
for (var i = 0; i < requiredPairs; i++) {
var symbol = availableSymbols[i];
symbols.push(symbol);
symbols.push(symbol);
}
// Shuffle
shuffleArray(symbols);
}
// Fisher-Yates shuffle algorithm
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;
}
}
// Create game board
function createBoard() {
var boardWidth = cols * cardWidth + (cols - 1) * cardSpacing;
var boardHeight = rows * cardHeight + (rows - 1) * cardSpacing;
var startX = (2048 - boardWidth) / 2 + cardWidth / 2;
var startY = (2732 - boardHeight) / 2 + cardHeight / 2;
var index = 0;
for (var r = 0; r < rows; r++) {
for (var c = 0; c < cols; c++) {
var x = startX + c * (cardWidth + cardSpacing);
var y = startY + r * (cardHeight + cardSpacing);
var symbol = symbols[index];
var soundId = soundMap[symbol] || null;
var imageId = 'animal_' + symbol; // Assuming images are named like 'animal_A', 'animal_B', etc.
var card = new Card(imageId, soundId);
card.x = x;
card.y = y;
game.addChild(card);
cards.push(card);
index++;
}
}
}
// Check for match when two cards are flipped
function checkForMatch() {
var card1 = flippedCards[0];
var card2 = flippedCards[1];
LK.setTimeout(function () {
if (card1.symbol === card2.symbol) {
// Match found
LK.getSound('match').play();
card1.showMatch();
card2.showMatch();
matchedPairs++;
// Update score
LK.setScore(LK.getScore() + 100);
scoreText.setText(LK.getScore());
// Check if all pairs are matched
if (matchedPairs === requiredPairs) {
gameWon();
}
} else {
// No match, flip cards back
LK.getSound('nomatch').play();
card1.reset();
card2.reset();
}
flippedCards = [];
}, 1000);
}
// Timer update
function updateTimer() {
timeLeft--;
timerText.setText("Time: " + timeLeft);
// Time running out warning
if (timeLeft <= 10 && !timeWarningGiven) {
timeWarningGiven = true;
timerText.setStyle({
fill: 0xE74C3C
});
LK.getSound('timewarning').play();
}
// Game over if time runs out
if (timeLeft <= 0) {
gameOver();
}
}
// Game won
function gameWon() {
LK.clearInterval(gameTimer);
gameActive = false;
// Add time bonus
var timeBonus = timeLeft * 10;
LK.setScore(LK.getScore() + timeBonus);
scoreText.setText(LK.getScore());
// Update high score
if (LK.getScore() > storage.highScore) {
storage.highScore = LK.getScore();
}
// Update level
level++;
if (level > 5) {
level = 1; // Reset to level 1 after level 5
}
storage.currentLevel = level;
// Play win sound
LK.getSound('win').play();
// Show success message
LK.showYouWin();
}
// Game over
function gameOver() {
LK.clearInterval(gameTimer);
gameActive = false;
// Show game over screen
LK.showGameOver();
}
// Start a new game
function startGame() {
// Reset game state
matchedPairs = 0;
flippedCards = [];
timeWarningGiven = false;
LK.setScore(0);
scoreText.setText("0");
// Clear previous game
for (var i = 0; i < cards.length; i++) {
cards[i].destroy();
}
cards = [];
// Set up new game
setDifficulty();
createSymbols();
createBoard();
// Reset timer
timerText.setText("Time: " + timeLeft);
timerText.setStyle({
fill: 0xFFFFFF
});
// Start timer
if (gameTimer) {
LK.clearInterval(gameTimer);
}
gameTimer = LK.setInterval(updateTimer, 1000);
// Start game
gameActive = true;
// Play background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
});
}
// Create UI elements
var titleText = new Text2("Flip & Match: Sound Safari", {
size: 80,
fill: 0xF1C40F
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
var scoreText = new Text2("0", {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -10;
scoreText.y = 50;
var timerText = new Text2("Time: 60", {
size: 60,
fill: 0x000000
});
timerText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(timerText);
timerText.y = -10;
var levelText = new Text2("Level: " + level, {
size: 60,
fill: 0x000000
});
levelText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(levelText);
levelText.y = -50;
// Start the game
LK.setTimeout(function () {
startGame();
}, 500);
// Main game update loop
game.update = function () {
// Update level text (in case level changes)
levelText.setText("Level: " + level);
}; ===================================================================
--- original.js
+++ change.js
@@ -347,22 +347,22 @@
var scoreText = new Text2("0", {
size: 60,
fill: 0xFFFFFF
});
-scoreText.anchor.set(0, 0);
-LK.gui.topLeft.addChild(scoreText);
-scoreText.x = 120; // Leave space for menu icon
-scoreText.y = 100;
+scoreText.anchor.set(1, 0);
+LK.gui.topRight.addChild(scoreText);
+scoreText.x = -10;
+scoreText.y = 50;
var timerText = new Text2("Time: 60", {
size: 60,
fill: 0x000000
});
-timerText.anchor.set(1, 0);
-LK.gui.topRight.addChild(timerText);
-timerText.y = 50;
+timerText.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(timerText);
+timerText.y = -10;
var levelText = new Text2("Level: " + level, {
size: 60,
- fill: 0xFFFFFF
+ fill: 0x000000
});
levelText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(levelText);
levelText.y = -50;
sheep. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
generate a cute cat image. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
generate a elephant. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
generate a monkey. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
lion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a colorful parrot. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
generate a butterfly. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
dolphin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows