User prompt
Remove the poison food item.
User prompt
All objects should disappear when the snake touches them."
User prompt
I have updated the image for the food named 'poison,' and it should disappear when eaten
User prompt
"Add a new food item to the game that looks like a real 2D bomb. Each time the snake eats this bomb, its health decreases by 20." 2. "Existing non-healing food items should disappear when eaten."
User prompt
1- Show the 'Seni seviyorum' message inside the container or panel used for the health bar visual. 2 - Rocks and poisonous food should be treated as different types of obstacles. Normal poisonous food reduces health by 20.
User prompt
"Rock obstacles reduce the snake's health by 70 on the first collision, and the snake dies on the second collision."
User prompt
1. "Rock obstacles reduce the snake's health by 70 on the first collision, and the snake dies on the second collision." 2. "Every time the score increases by 200, make the poison food items more visible on the screen."
User prompt
Add a health bar starting at 100. The health bar should show green for the remaining health and red for the missing health, displayed inside a box.
User prompt
Delete or hide the health bar UI element.
User prompt
Replace the 'I love you' message with 'Seni seviyorum' and show it inside a bordered box or panel
User prompt
At score 100, replace the placeholder rock obstacle sprites with actual rock images
User prompt
"When the score reaches 200, remove the obstacles that appeared at score 100." "When the score reaches 300, display the message 'I love you' on the screen for 1 second, then remove it." ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Spawn 3 poisonous food items on the screen for every 3 normal food items that appear
User prompt
Increase the score by 50 every time the snake eats food.
User prompt
1. "Increase the score as the snake eats food. When the score passes 100, spawn more poison obstacles around the area along with some wall-like rocks." 2. "When the snake collides with these rocks, the snake dies."
User prompt
1-Ensure that the background does not cover or interfere with the visibility of the snake's body and any particle effects 2- have a comet (or shooting star) effect follow behind the snake
User prompt
The snake should have a health bar of 100 displayed below the score. Each time the snake eats poison, the health decreases by 40. When health drops below 0, the snake dies.
User prompt
The snake should have a health bar of 100 displayed below the score. Each time the snake eats poison, the health decreases by 40. When health drops below 0, the snake dies.
User prompt
Each time the snake consumes a poison obstacle, reduce the health bar value by 10
User prompt
"Place several obstacles around the area, and if the snake hits any of them, the snake dies." "Add more poison obstacles once the score passes 300." "Add a health bar just below the score display."
User prompt
1-Ensure that the background does not cover or interfere with the visibility of the snake's body and any particle effects 2- have a comet (or shooting star) effect follow behind the snake
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'head.filters = [{' Line Number: 166
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'head.filters = [{' Line Number: 166
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'head.filters = [{' Line Number: 166
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'head.filters = [{' Line Number: 166
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var BodyPart = Container.expand(function () { var self = Container.call(this); var bodyPart = self.attachAsset('head', { anchorX: 0.5, anchorY: 0.5 }); // Add animation properties self.originalScale = 1; self.isAnimating = false; self.animationDirection = 1; // Rotate the body part based on direction self.setDirection = function (direction) { if (direction === 'up') { bodyPart.rotation = 0; } else if (direction === 'down') { bodyPart.rotation = Math.PI; } else if (direction === 'left') { bodyPart.rotation = -Math.PI / 2; } else if (direction === 'right') { bodyPart.rotation = Math.PI / 2; } }; // Start wiggle animation for body parts self.startWiggleAnimation = function () { if (self.isAnimating) return; self.isAnimating = true; self.animateWiggle(); }; // Stop wiggle animation self.stopWiggleAnimation = function () { self.isAnimating = false; tween.stop(bodyPart, { scaleX: true, scaleY: true }); bodyPart.scaleX = self.originalScale; bodyPart.scaleY = self.originalScale; }; // Animate wiggle effect self.animateWiggle = function () { if (!self.isAnimating) return; var scaleOffset = 0.05; var duration = 250; // Determine which axis to animate based on direction var direction = self.animationDirection; var targetScaleX = self.originalScale; var targetScaleY = self.originalScale; // Wiggle based on body orientation if (bodyPart.rotation === 0 || bodyPart.rotation === Math.PI) { // For up/down movement, wiggle horizontally targetScaleX = self.originalScale + scaleOffset * direction; } else { // For left/right movement, wiggle vertically targetScaleY = self.originalScale + scaleOffset * direction; } tween(bodyPart, { scaleX: targetScaleX, scaleY: targetScaleY }, { duration: duration, easing: tween.easeInOut, onFinish: function onFinish() { self.animationDirection *= -1; if (self.isAnimating) { self.animateWiggle(); } } }); }; return self; }); var BonusFood = Container.expand(function () { var self = Container.call(this); // Create the bonus food var bonusFood = self.attachAsset('bonusFood', { anchorX: 0.5, anchorY: 0.5 }); }); var Food = Container.expand(function () { var self = Container.call(this); // Create the food var food = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5 }); }); var Life = Container.expand(function () { var self = Container.call(this); // Create the life var life = self.attachAsset('life', { anchorX: 0.5, anchorY: 0.5 }); }); var Pause = Container.expand(function () { var self = Container.call(this); // Create the pause button var pause = self.attachAsset('pause', { anchorX: 0.5, anchorY: 0.5 }); // Event handler called when a press happens on element. self.down = function (x, y, obj) { if (!game.paused) { game.paused = true; pause.id = 'resume'; } else { game.paused = false; pause.id = 'pause'; } }; }); var Poison = Container.expand(function () { var self = Container.call(this); // Create the poison var poison = self.attachAsset('poison', { anchorX: 0.5, anchorY: 0.5 }); }); var Rock = Container.expand(function () { var self = Container.call(this); // Create a rock obstacle using a shape asset tinted like a rock var rock = self.attachAsset('poison', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); // Make it look like a rock with gray tint rock.tint = 0x777777; return self; }); var Snake = Container.expand(function () { var self = Container.call(this); // Create the head of the snake var head = self.attachAsset('head', { anchorX: 0.5, anchorY: 0.5 }); // Initialize the snake's direction and speed self.direction = 'up'; self.speed = 5; self.previousPositions = []; // Update the head rotation based on direction self.updateHeadRotation = function () { if (self.direction === 'up') { head.rotation = 0; } else if (self.direction === 'down') { head.rotation = Math.PI; } else if (self.direction === 'left') { head.rotation = -Math.PI / 2; } else if (self.direction === 'right') { head.rotation = Math.PI / 2; } }; self.moveHead = function (newDirection) { if (newDirection === 'up' && this.direction !== 'down') { this.direction = 'up'; self.updateHeadRotation(); } else if (newDirection === 'down' && this.direction !== 'up') { this.direction = 'down'; self.updateHeadRotation(); } else if (newDirection === 'left' && this.direction !== 'right') { this.direction = 'left'; self.updateHeadRotation(); } else if (newDirection === 'right' && this.direction !== 'left') { this.direction = 'right'; self.updateHeadRotation(); } }; // Initialize with the correct rotation self.updateHeadRotation(); return self; }); var StarTrail = Container.expand(function () { var self = Container.call(this); // Create a star-like shape using an asset var star = self.attachAsset('food', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5 }); // Set initial properties self.alpha = 1; self.fadeSpeed = 0.05; self.rotationSpeed = 0.1; self.tailLength = 0; self.maxTailLength = 30; self.growSpeed = 0.5; self.tailColor = 0xFFFF99; // Light yellow for tail star.tint = 0xFFFFFF; // White for star head // Update method to handle fading, rotation and tail growth self.update = function () { // Rotate the star star.rotation += self.rotationSpeed; // Fade out self.alpha -= self.fadeSpeed; // Grow tail initially if (self.tailLength < self.maxTailLength) { self.tailLength += self.growSpeed; } // If fully transparent, mark for removal if (self.alpha <= 0) { self.shouldRemove = true; } }; return self; }); /**** * Initialize Game ****/ //<Assets used in the game will automatically appear here> var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Add a background to the game // Import tween plugin for animations var background = game.addChildAt(LK.getAsset('newBackground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2, alpha: 0.7 // Reduce opacity to improve visibility of game elements }), 0); // Add background as the bottom-most layer // Initialize pause button var pause = game.addChild(new Pause()); // Position the pause button a little to the left from the top right corner of the game pause.x = 2048 - pause.width; pause.y = 50; // Move the pause button a little down var snake = game.addChild(new Snake()); snake.body = []; // Position the snake at the center of the game snake.x = 2048 / 2; snake.y = 2732 / 2; // Initialize food var food = game.addChild(new Food()); // Position the food at a random location within the game food.x = Math.random() * 2048; food.y = Math.random() * 2732; // Initialize poison var bonusFood = game.addChild(new BonusFood()); // Hide the bonus food when the game starts bonusFood.x = -100; bonusFood.y = -100; var poison = game.addChild(new Poison()); // Initialize life var life = game.addChild(new Life()); // Hide the life when the game starts life.x = -100; life.y = -100; // Hide the poison when the game starts poison.x = -100; poison.y = -100; game.update = function () { if (game.paused) { return; } // Update the snake's position based on its direction and speed if (snake.direction === 'up') { snake.y -= snake.speed * 2.25; } else if (snake.direction === 'down') { snake.y += snake.speed * 2.25; } else if (snake.direction === 'left') { snake.x -= snake.speed * 2.25; } else if (snake.direction === 'right') { snake.x += snake.speed * 2.25; } // Store the current position of the snake head snake.previousPositions.unshift({ x: snake.x, y: snake.y, direction: snake.direction }); // Limit the previous positions array to the length of the body plus some buffer if (snake.previousPositions.length > snake.body.length + 10) { snake.previousPositions.pop(); } // Update the position of the body parts to follow the head's previous positions for (var i = 0; i < snake.body.length; i++) { if (i + 1 < snake.previousPositions.length) { // Make sure the body part is added to the game at the bottom layer // to ensure it stays behind the head game.addChildAt(snake.body[i], 0); // Position the body part based on the previous position of the head snake.body[i].x = snake.previousPositions[i + 1].x; snake.body[i].y = snake.previousPositions[i + 1].y; snake.body[i].setDirection(snake.previousPositions[i + 1].direction); // Manage animation for body parts // Start animation if not already animating if (!snake.body[i].isAnimating) { snake.body[i].startWiggleAnimation(); } // Set animation phase offset based on position in snake body // This creates a wave-like effect through the snake's body snake.body[i].animationDirection = i % 2 === 0 ? 1 : -1; // Create star trail effect behind the last body part (once every few frames) if (i === snake.body.length - 1 && LK.ticks % 3 === 0) { var star = new StarTrail(); star.x = snake.body[i].x; star.y = snake.body[i].y; // Add some randomness to position for more organic feel star.x += Math.random() * 10 - 5; star.y += Math.random() * 10 - 5; // Place star trail behind the snake but above the background game.addChildAt(star, game.getChildIndex(background) + 1); if (!starTrails) { starTrails = []; } starTrails.push(star); } } } // Update and clean up star trails if (starTrails) { for (var j = starTrails.length - 1; j >= 0; j--) { starTrails[j].update(); // Create comet trail effect with gradual color change if (starTrails[j].tailLength > 0 && LK.ticks % 2 === 0) { // Calculate color based on alpha var colorIntensity = Math.floor(starTrails[j].alpha * 255); var tailColor = colorIntensity << 16 | colorIntensity << 8 | Math.floor(colorIntensity * 0.7); // Apply color tint to create glowing effect if (starTrails[j].children[0]) { starTrails[j].children[0].tint = tailColor; } // Scale effect for comet-like appearance var scaleFactor = 0.5 + starTrails[j].alpha * 0.5; starTrails[j].scaleX = scaleFactor; starTrails[j].scaleY = scaleFactor; } if (starTrails[j].shouldRemove) { starTrails[j].destroy(); starTrails.splice(j, 1); } } } // Check if the snake's head intersects with the food if (snake.intersects(food)) { // Increase the score by 50 instead of 10 score += 50; // Update the score text scoreTxt.setText('Score: ' + score); // Increase the food consumed count foodConsumed += 1; // Track normal food items for poison spawning normalFoodCount += 1; // Every 3 normal food items, trigger spawning of 3 poison items if (normalFoodCount >= 3) { poisonToSpawn += 3; normalFoodCount = 0; } // Add a new body part to the snake var newBodyPart = new BodyPart(); // Set the direction of the new body part newBodyPart.setDirection(snake.direction); // If no previous positions exist, create initial position if (snake.previousPositions.length <= snake.body.length) { var lastPos; if (snake.body.length === 0) { lastPos = { x: snake.x, y: snake.y }; } else { var lastBodyPart = snake.body[snake.body.length - 1]; lastPos = { x: lastBodyPart.x, y: lastBodyPart.y }; } // Calculate position based on direction if (snake.direction === 'up') { newBodyPart.x = lastPos.x; newBodyPart.y = lastPos.y + 50; // Use a fixed offset } else if (snake.direction === 'down') { newBodyPart.x = lastPos.x; newBodyPart.y = lastPos.y - 50; } else if (snake.direction === 'left') { newBodyPart.x = lastPos.x + 50; newBodyPart.y = lastPos.y; } else if (snake.direction === 'right') { newBodyPart.x = lastPos.x - 50; newBodyPart.y = lastPos.y; } } else { // Use the position from previous positions array var pos = snake.previousPositions[snake.body.length]; newBodyPart.x = pos.x; newBodyPart.y = pos.y; } // Initialize animation properties and start animation for the new body part newBodyPart.startWiggleAnimation(); // Add scale animation when adding new body part newBodyPart.scaleX = 0; newBodyPart.scaleY = 0; tween(newBodyPart, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.easeOutElastic }); snake.body.push(newBodyPart); game.addChild(newBodyPart); // Create an initial burst of star trail when a new body part is added for (var s = 0; s < 10; s++) { var star = new StarTrail(); star.x = newBodyPart.x + (Math.random() * 60 - 30); star.y = newBodyPart.y + (Math.random() * 60 - 30); star.alpha = 0.8 + Math.random() * 0.2; star.fadeSpeed = 0.03 + Math.random() * 0.02; star.rotationSpeed = 0.05 + Math.random() * 0.1; // Place star above background but below game elements game.addChildAt(star, game.getChildIndex(background) + 1); starTrails.push(star); } // Check if it's time to show the bonus food if (score % 150 === 0) { // Position the bonus food at a new random location within the game, ensuring it does not appear on the border do { bonusFood.x = Math.random() * (2048 - bonusFood.width) + bonusFood.width / 2; bonusFood.y = Math.random() * (2732 - bonusFood.height) + bonusFood.height / 2; } while ((bonusFood.x < 100 || bonusFood.x > 1948) && (bonusFood.y < 100 || bonusFood.y > 2632)); // Show the bonus food for 8 seconds LK.setTimeout(function () { bonusFood.x = -100; bonusFood.y = -100; }, 8000); } // Display "I love you" message when score reaches 300 if (score >= 300 && !messageDisplayed) { // Create a flag to track whether the message has been displayed messageDisplayed = true; // Create a message text var loveMessage = new Text2('I love you', { size: 72, fill: 0xFF00FF }); // Center the message loveMessage.anchor.set(0.5, 0.5); // Add message to the center of the screen LK.gui.center.addChild(loveMessage); // Start with zero scale and fade in loveMessage.scaleX = 0; loveMessage.scaleY = 0; // Animate the message appearance tween(loveMessage, { scaleX: 1, scaleY: 1, alpha: 1 }, { duration: 500, easing: tween.elasticOut }); // Remove the message after 1 second LK.setTimeout(function () { // Fade out and remove tween(loveMessage, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 500, easing: tween.backIn, onFinish: function onFinish() { LK.gui.center.removeChild(loveMessage); } }); }, 1000); } // Check if it's time to show the life if (score !== 0 && score % 100 === 0 && score != previousScore) { previousScore = score; // Position the life at a new random location within the game, ensuring it does not appear on the border do { life.x = Math.random() * (2048 - life.width) + life.width / 2; life.y = Math.random() * (2732 - life.height) + life.height / 2; } while ((life.x < 100 || life.x > 1948) && (life.y < 100 || life.y > 2632)); // Show the life for 10 seconds LK.setTimeout(function () { life.x = -100; life.y = -100; }, 10000); } // Check if there are poison items to spawn if (poisonToSpawn > 0) { // Position the original poison at a new random location within the game do { poison.x = Math.random() * (2048 - poison.width) + poison.width / 2; poison.y = Math.random() * (2732 - poison.height) + poison.height / 2; } while ((poison.x < 100 || poison.x > 1948) && (poison.y < 100 || poison.y > 2632)); // Show the poison for 8 seconds LK.setTimeout(function () { poison.x = -100; poison.y = -100; }, 8000); // Spawn additional poison items if needed if (poisonToSpawn > 1) { for (var p = 0; p < Math.min(poisonToSpawn - 1, 2); p++) { var extraPoison = new Poison(); do { extraPoison.x = Math.random() * (2048 - extraPoison.width) + extraPoison.width / 2; extraPoison.y = Math.random() * (2732 - extraPoison.height) + extraPoison.height / 2; } while ((extraPoison.x < 100 || extraPoison.x > 1948) && (extraPoison.y < 100 || extraPoison.y > 2632)); game.addChild(extraPoison); // Hide the extra poison after 8 seconds (function (poisonObj) { LK.setTimeout(function () { poisonObj.destroy(); }, 8000); })(extraPoison); } } poisonToSpawn = 0; } // Spawn more poison and rocks when score passes 100 if (score > 100 && score < 200 && rocks.length === 0) { // Spawn 5 rocks in random positions for (var r = 0; r < 5; r++) { var rock = new Rock(); // Position rocks randomly but avoid placing directly on snake do { rock.x = Math.random() * (2048 - 200) + 100; rock.y = Math.random() * (2732 - 200) + 100; } while (Math.abs(rock.x - snake.x) < 200 && Math.abs(rock.y - snake.y) < 200); game.addChild(rock); rocks.push(rock); } // Also add an extra poison obstacle var extraPoison = new Poison(); do { extraPoison.x = Math.random() * (2048 - 200) + 100; extraPoison.y = Math.random() * (2732 - 200) + 100; } while (Math.abs(extraPoison.x - snake.x) < 200 && Math.abs(extraPoison.y - snake.y) < 200); game.addChild(extraPoison); } // Remove rocks when score reaches 200 if (score >= 200 && rocks.length > 0) { // Remove all rocks for (var i = rocks.length - 1; i >= 0; i--) { rocks[i].destroy(); rocks.splice(i, 1); } } // Position the food at a new random location within the game, ensuring it does not appear on the border do { food.x = Math.random() * (2048 - food.width) + food.width / 2; food.y = Math.random() * (2732 - food.height) + food.height / 2; } while ((food.x < 100 || food.x > 1948) && (food.y < 100 || food.y > 2632)); // Play baby sound when food is eaten LK.getSound('yiyecek').play(); } // Check if the snake's head intersects with the bonus food if (snake.intersects(bonusFood)) { // Increase the score by 50 score += 50; // Update the score text scoreTxt.setText('Score: ' + score); // Play the bonus food sound LK.getSound('bonusfood').play(); // Hide the bonus food bonusFood.x = -100; bonusFood.y = -100; } // Check if the snake's head intersects with the life if (snake.intersects(life)) { // Increase the lives by 1, up to a maximum of 8 if (lives < 8) { lives += 1; // Update the lives text livesTxt.setText('Lives: ' + lives); // Play the life sound LK.getSound('life').play(); } // Hide the life life.x = -100; life.y = -100; } // Check if the snake's head intersects with the poison if (snake.intersects(poison)) { // Decrease the lives lives -= 1; // Update the lives text livesTxt.setText('Lives: ' + lives); // Decrease health by 40 health -= 40; // Update health display healthTxt.setText('Health: ' + health); // Update health bar width based on health percentage var healthPercent = Math.max(0, health / 100); healthBar.scaleX = healthPercent; // Health bar color changes based on health level if (health <= 30) { healthBarGraphic.tint = 0xFF0000; // Red for low health } else if (health <= 60) { healthBarGraphic.tint = 0xFFAA00; // Orange for medium health } else { healthBarGraphic.tint = 0x00FF00; // Green for high health } // Play the poison sound LK.getSound('poison').play(); // Hide the poison poison.x = -100; poison.y = -100; // Reset the food consumed count after consuming poison foodConsumed = 0; // Check if health has hit 0 or lives have hit 0 if (health <= 0 || lives === 0) { // Show game over LK.getSound('GameOver').play(); LK.showGameOver(); } } // Check if the snake's head has moved out of the screen if (snake.x < 0) { snake.x = 2048; } else if (snake.x > 2048) { snake.x = 0; } else if (snake.y < 0) { snake.y = 2732; } else if (snake.y > 2732) { snake.y = 0; } // Check for collision with rocks for (var r = 0; r < rocks.length; r++) { if (snake.intersects(rocks[r])) { // Snake dies immediately when it hits a rock LK.getSound('GameOver').play(); // Flash screen red for visual feedback LK.effects.flashScreen(0xFF0000, 500); LK.showGameOver(); break; } } }; // Initialize lives, score, food consumed and poison generated var lives = 3; var score = 0; var previousScore = 0; var foodConsumed = 0; var poisonGenerated = false; var normalFoodCount = 0; // Track normal food items spawned var poisonToSpawn = 0; // Track how many poison items to spawn var starTrails = []; var rocks = []; // Array to hold rock obstacles var messageDisplayed = false; // Flag to track if "I love you" message has been displayed // Create lives text var livesTxt = new Text2('Lives: ' + lives, { size: 32, fill: 0xFFFFFF }); livesTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(livesTxt); // Create score text var scoreTxt = new Text2('Score: ' + score, { size: 32, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize health var health = 100; // Create health text var healthTxt = new Text2('Health: ' + health, { size: 32, fill: 0xFFFFFF }); healthTxt.anchor.set(0.5, 0); healthTxt.y = scoreTxt.y + scoreTxt.height + 10; // Position below score LK.gui.top.addChild(healthTxt); // Create health bar background var healthBarBg = new Container(); var healthBarBgGraphic = healthBarBg.attachAsset('healbar', { anchorX: 0.5, anchorY: 0.5, tint: 0x444444 }); healthBarBg.width = 200; healthBarBg.height = 20; healthBarBg.x = 0; healthBarBg.y = healthTxt.y + healthTxt.height + 5; LK.gui.top.addChild(healthBarBg); // Create health bar var healthBar = new Container(); var healthBarGraphic = healthBar.attachAsset('healbar', { anchorX: 0.5, anchorY: 0.5, tint: 0x00FF00 }); healthBar.width = 200; healthBar.height = 20; healthBar.x = 0; healthBar.y = healthTxt.y + healthTxt.height + 5; LK.gui.top.addChild(healthBar); game.down = function (x, y, obj) { if (game.paused) { return; } // Change the snake's direction to always move in the direction of the front area of the snake head which is not connected to the snake body if (x > snake.x && snake.direction !== 'left' && snake.direction !== 'right') { snake.moveHead('right'); } else if (x < snake.x && snake.direction !== 'right' && snake.direction !== 'left') { snake.moveHead('left'); } else if (y > snake.y && snake.direction !== 'up' && snake.direction !== 'down') { snake.moveHead('down'); } else if (y < snake.y && snake.direction !== 'down' && snake.direction !== 'up') { snake.moveHead('up'); } };
===================================================================
--- original.js
+++ change.js
@@ -442,8 +442,49 @@
bonusFood.x = -100;
bonusFood.y = -100;
}, 8000);
}
+ // Display "I love you" message when score reaches 300
+ if (score >= 300 && !messageDisplayed) {
+ // Create a flag to track whether the message has been displayed
+ messageDisplayed = true;
+ // Create a message text
+ var loveMessage = new Text2('I love you', {
+ size: 72,
+ fill: 0xFF00FF
+ });
+ // Center the message
+ loveMessage.anchor.set(0.5, 0.5);
+ // Add message to the center of the screen
+ LK.gui.center.addChild(loveMessage);
+ // Start with zero scale and fade in
+ loveMessage.scaleX = 0;
+ loveMessage.scaleY = 0;
+ // Animate the message appearance
+ tween(loveMessage, {
+ scaleX: 1,
+ scaleY: 1,
+ alpha: 1
+ }, {
+ duration: 500,
+ easing: tween.elasticOut
+ });
+ // Remove the message after 1 second
+ LK.setTimeout(function () {
+ // Fade out and remove
+ tween(loveMessage, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 500,
+ easing: tween.backIn,
+ onFinish: function onFinish() {
+ LK.gui.center.removeChild(loveMessage);
+ }
+ });
+ }, 1000);
+ }
// Check if it's time to show the life
if (score !== 0 && score % 100 === 0 && score != previousScore) {
previousScore = score;
// Position the life at a new random location within the game, ensuring it does not appear on the border
@@ -488,9 +529,9 @@
}
poisonToSpawn = 0;
}
// Spawn more poison and rocks when score passes 100
- if (score > 100 && rocks.length === 0) {
+ if (score > 100 && score < 200 && rocks.length === 0) {
// Spawn 5 rocks in random positions
for (var r = 0; r < 5; r++) {
var rock = new Rock();
// Position rocks randomly but avoid placing directly on snake
@@ -508,8 +549,16 @@
extraPoison.y = Math.random() * (2732 - 200) + 100;
} while (Math.abs(extraPoison.x - snake.x) < 200 && Math.abs(extraPoison.y - snake.y) < 200);
game.addChild(extraPoison);
}
+ // Remove rocks when score reaches 200
+ if (score >= 200 && rocks.length > 0) {
+ // Remove all rocks
+ for (var i = rocks.length - 1; i >= 0; i--) {
+ rocks[i].destroy();
+ rocks.splice(i, 1);
+ }
+ }
// Position the food at a new random location within the game, ensuring it does not appear on the border
do {
food.x = Math.random() * (2048 - food.width) + food.width / 2;
food.y = Math.random() * (2732 - food.height) + food.height / 2;
@@ -609,8 +658,9 @@
var normalFoodCount = 0; // Track normal food items spawned
var poisonToSpawn = 0; // Track how many poison items to spawn
var starTrails = [];
var rocks = []; // Array to hold rock obstacles
+var messageDisplayed = false; // Flag to track if "I love you" message has been displayed
// Create lives text
var livesTxt = new Text2('Lives: ' + lives, {
size: 32,
fill: 0xFFFFFF
Pause icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
havuç. In-Game asset. 2d. High contrast. No shadows
çilek. In-Game asset. 2d. High contrast. No shadows
boynuna bir kurdele ve eline de uçan bir balon
böğürtlen ormanı. In-Game asset. 2d. High contrast. No shadows
taş. In-Game asset. 2d. High contrast. No shadows
mesaj kutusu. In-Game asset. 2d. High contrast. No shadows