User prompt
change the background color to this #2f4a01
User prompt
Use this color for the game background #558c45
User prompt
Make the dark green background little light green
User prompt
Make a starting screen before the game starts, with the title and a button which says start
User prompt
add Sounds for flipping the tile, matching the pairs, for errors, gaining hearts, and loosing heart
User prompt
There should be only 11 animals, because we are pairing for each level
User prompt
Restrict until level 10, when people reach 10 they win. So the tiles should start at 4 and then add +2 for each level also create assets accordingly
User prompt
For level 1 only have 4 tiles, then add +2 for each progressing level
User prompt
Create like multiple assets for the tiles to match them, ( just with numbers or alphabets )
Code edit (1 edits merged)
Please save this source code
User prompt
Forest Critter Memory Match
Initial prompt
The game theme is "Forest Animal Hide-and-seek" -> Hidden forest critters ( fox, owl, raccoons, plants etc.. ) Main mechanism: -> Starting screen : Put title of the game on the top of the Screen, and a button at the middle saying start -> Game screen: -> Players get 10 hearts at the start of the game -> There are infinite levels of this game -> Each level gives players to test their memory, by using tiles as place to hide an image of an animal, that has pairs, when flipped both of them, the player gets a point ( Example: there can be 10 tiles, there 2 of them has same animal image, but everything is flipped back, players should click them to reveal them, and selecting two of the same tiles ( with same animal image) gives 1 point to the player and the flipped tile will be taken away, if the player flip two different image of the animal tiles, it will be flipped back hiding the image.) -> If the player flip two different image 3 times a row, 1 heart will be taken out. warn the player after 2 wrong tries with a shaking screen or an owl "hoot" to add drama.( give like a combo mechanism with cool sound, saying flipping same pairs of images 2 times a row starts the combo, doing further multiplies the point gained ). -> The game should progress like levels: Level 1: 4 tiles (2 pairs) Level 2: 6 tiles (3 pairs) Level 3: 8 tiles (4 pairs) Level 4: 12 tiles (6 pairs) Level 5: 16 tiles (8 pairs) Level 6: 20 tiles (10 pairs) → Then +4 per level or based on difficulty. -> When players complete levels ( count only levels after 3) they gain 2 extra hearts. -> When the player depletes all hearts the game ends.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Tile class: represents a single memory tile var Tile = Container.expand(function () { var self = Container.call(this); // Properties self.isFlipped = false; self.isMatched = false; self.animalId = null; // Will be set on creation // Create the back of the tile (hidden state) var back = self.attachAsset('tileBack', { anchorX: 0.5, anchorY: 0.5 }); // Create the front of the tile (animal/plant) var front = self.attachAsset('animal0', { // Placeholder, will be replaced anchorX: 0.5, anchorY: 0.5, visible: false }); self.back = back; self.front = front; // Set animal asset self.setAnimal = function (animalId) { self.animalId = animalId; // Remove old front if exists if (self.front) { self.removeChild(self.front); } // Attach new front self.front = self.attachAsset('animal' + animalId, { anchorX: 0.5, anchorY: 0.5, visible: false }); }; // Flip to show animal self.flipUp = function () { if (self.isFlipped || self.isMatched) return; self.isFlipped = true; // Animate flip tween(self, { scaleX: 0 }, { duration: 100, easing: tween.easeIn, onFinish: function onFinish() { self.back.visible = false; self.front.visible = true; tween(self, { scaleX: 1 }, { duration: 100, easing: tween.easeOut }); } }); }; // Flip to hide animal self.flipDown = function () { if (!self.isFlipped || self.isMatched) return; self.isFlipped = false; tween(self, { scaleX: 0 }, { duration: 100, easing: tween.easeIn, onFinish: function onFinish() { self.front.visible = false; self.back.visible = true; tween(self, { scaleX: 1 }, { duration: 100, easing: tween.easeOut }); } }); }; // Mark as matched (permanently face up) self.setMatched = function () { self.isMatched = true; self.isFlipped = true; self.back.visible = false; self.front.visible = true; // Optional: animate a little pop tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeIn }); } }); }; // Handle tap self.down = function (x, y, obj) { if (self.isFlipped || self.isMatched || !canFlipTiles) return; onTileFlipped(self); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2e4d2c // Forest green }); /**** * Game Code ****/ // Animal tile assets: numbers 0-9 and letters A, B // --- Game variables --- var animalCount = 12; // Number of unique animals/plants (animal0 ... animal11) var tileBackColor = 0x8db580; // Light green for tile back var tileSize = 260; // px, square var tilePadding = 32; // px var minBoardMargin = 60; // px, margin from edge var level = 1; var hearts = 10; var score = 0; var combo = 0; var maxCombo = 0; var consecutiveMisses = 0; var tiles = []; var flippedTiles = []; var canFlipTiles = true; var pairsLeft = 0; // --- UI elements --- var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var heartsTxt = new Text2('♥ 10', { size: 90, fill: 0xFF4D4D }); heartsTxt.anchor.set(0.5, 0); LK.gui.top.addChild(heartsTxt); heartsTxt.y = 120; heartsTxt.x = 0; var levelTxt = new Text2('Level 1', { size: 90, fill: 0xFFE066 }); levelTxt.anchor.set(0.5, 0); LK.gui.top.addChild(levelTxt); levelTxt.y = 220; levelTxt.x = 0; // --- Asset initialization (shapes for tile back, animal images) --- for (var i = 0; i < animalCount; i++) {} // --- Helper: shuffle array --- function shuffle(arr) { for (var i = arr.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var t = arr[i]; arr[i] = arr[j]; arr[j] = t; } return arr; } // --- Helper: update UI --- function updateUI() { scoreTxt.setText(score); heartsTxt.setText('♥ ' + hearts); levelTxt.setText('Level ' + level); } // --- Helper: show all tiles for preview --- function previewTiles(cb) { canFlipTiles = false; for (var i = 0; i < tiles.length; i++) { tiles[i].flipUp(); } LK.setTimeout(function () { for (var i = 0; i < tiles.length; i++) { tiles[i].flipDown(); } canFlipTiles = true; if (cb) cb(); }, 1200 + Math.min(600, level * 100)); } // --- Helper: create board for current level --- function createBoard() { // Remove old tiles for (var i = 0; i < tiles.length; i++) { tiles[i].destroy(); } tiles = []; flippedTiles = []; canFlipTiles = false; // Determine number of tiles for this level // Level 1: 4 tiles (2 pairs), then +2 tiles per level var tileCount = 4 + (level - 1) * 2; var pairCount = Math.floor(tileCount / 2); if (pairCount > animalCount) pairCount = animalCount; // Cap to available animal assets tileCount = pairCount * 2; // Ensure even number // Find grid size (try to make as square as possible) var cols = Math.ceil(Math.sqrt(tileCount)); var rows = Math.ceil(tileCount / cols); // Prepare animal pairs var animalIds = []; for (var i = 0; i < pairCount; i++) { animalIds.push(i); animalIds.push(i); } shuffle(animalIds); // Board centering var boardW = cols * tileSize + (cols - 1) * tilePadding; var boardH = rows * tileSize + (rows - 1) * tilePadding; var startX = Math.floor((2048 - boardW) / 2) + tileSize / 2; var startY = Math.floor((2732 - boardH) / 2) + tileSize / 2; // Create tiles var idx = 0; for (var r = 0; r < rows; r++) { for (var c = 0; c < cols; c++) { if (idx >= animalIds.length) continue; var tile = new Tile(); tile.setAnimal(animalIds[idx]); tile.x = startX + c * (tileSize + tilePadding); tile.y = startY + r * (tileSize + tilePadding); tile.scaleX = 1; tile.scaleY = 1; game.addChild(tile); tiles.push(tile); idx++; } } pairsLeft = pairCount; updateUI(); previewTiles(function () { canFlipTiles = true; }); } // --- Tile flip handler --- function onTileFlipped(tile) { if (!canFlipTiles) return; if (tile.isFlipped || tile.isMatched) return; tile.flipUp(); flippedTiles.push(tile); if (flippedTiles.length === 2) { canFlipTiles = false; var t1 = flippedTiles[0]; var t2 = flippedTiles[1]; if (t1.animalId === t2.animalId) { // Match! LK.setTimeout(function () { t1.setMatched(); t2.setMatched(); pairsLeft--; combo++; maxCombo = Math.max(combo, maxCombo); score += 10 * combo; updateUI(); flippedTiles = []; canFlipTiles = true; consecutiveMisses = 0; // Animate match LK.effects.flashObject(t1, 0xFFFF99, 300); LK.effects.flashObject(t2, 0xFFFF99, 300); if (pairsLeft === 0) { // Level complete! LK.setTimeout(function () { nextLevel(); }, 800); } }, 400); } else { // Not a match LK.setTimeout(function () { t1.flipDown(); t2.flipDown(); flippedTiles = []; canFlipTiles = true; combo = 0; consecutiveMisses++; if (consecutiveMisses >= 3) { hearts--; consecutiveMisses = 0; LK.effects.flashScreen(0xff0000, 400); updateUI(); if (hearts <= 0) { LK.showGameOver(); return; } } updateUI(); }, 700); } } } // --- Next level --- function nextLevel() { level++; // Reward: extra heart for levels > 3 if (level > 3) { hearts++; LK.effects.flashScreen(0x66ff66, 400); } combo = 0; consecutiveMisses = 0; createBoard(); } // --- Start game --- function startGame() { level = 1; hearts = 10; score = 0; combo = 0; maxCombo = 0; consecutiveMisses = 0; createBoard(); } // --- Game update (not used for logic here) --- game.update = function () { // No per-frame logic needed }; // --- Start the game --- startGame();
===================================================================
--- original.js
+++ change.js
@@ -206,15 +206,17 @@
}
tiles = [];
flippedTiles = [];
canFlipTiles = false;
- // Determine board size
- // Level 1: 2x2 (2 pairs), Level 2: 3x4 (6 pairs), Level 3: 4x5 (10 pairs), Level 4+: 5x6 (15 pairs), etc.
- var pairCount = Math.min(2 + Math.floor(level * 1.5), Math.floor(animalCount / 2) * 2); // Max 12 pairs
- if (level >= 4) pairCount = Math.min(15, animalCount); // Cap at 12 pairs for now
+ // Determine number of tiles for this level
+ // Level 1: 4 tiles (2 pairs), then +2 tiles per level
+ var tileCount = 4 + (level - 1) * 2;
+ var pairCount = Math.floor(tileCount / 2);
+ if (pairCount > animalCount) pairCount = animalCount; // Cap to available animal assets
+ tileCount = pairCount * 2; // Ensure even number
// Find grid size (try to make as square as possible)
- var cols = Math.ceil(Math.sqrt(pairCount * 2));
- var rows = Math.ceil(pairCount * 2 / cols);
+ var cols = Math.ceil(Math.sqrt(tileCount));
+ var rows = Math.ceil(tileCount / cols);
// Prepare animal pairs
var animalIds = [];
for (var i = 0; i < pairCount; i++) {
animalIds.push(i);
Put like a wooden background
Put like a wooden background
make the rabbit cartoony
Cartoon deer with plane wooden background. In-Game asset. 2d. High contrast. No shadows
Owl Image with wooden background. In-Game asset. 2d. High contrast. No shadows
A scary lion image with wooden background. In-Game asset. 2d. High contrast. No shadows
A tiger image, with wooden background. In-Game asset. 2d. High contrast. No shadows
A beaver with wooden background. In-Game asset. 2d. High contrast. No shadows
Racoon image with wooden background. In-Game asset. 2d. High contrast. No shadows
Moose pic with wooden background. In-Game asset. 2d. High contrast. No shadows
Bear with wooden background. In-Game asset. 2d. High contrast. No shadows
A Wooden square tile with dark borders. In-Game asset. 2d. High contrast. No shadows