User prompt
исправить ошибку, когда противник не пересек игрока, но произошел гейм овер
User prompt
пересечение игрока и противника по заполненному изображению
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'global')' in or related to this line: 'targetPosition = game.toLocal(obj.global); // Set the target position to the cursor position if the screen is being pressed' Line Number: 193
Code edit (8 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
Code edit (2 edits merged)
Please save this source code
User prompt
каждые 3 секунды, увеличивать первоначальную скорость каждого препятствия на 50
User prompt
увеличить первоначальную скорость каждого препятствия на 20, если на таймера больше 3
User prompt
Increase the speed of each obstacle by 10 after 3 points are scored
User prompt
после набранных 10 очков, скорость каждого препятствия увеличивается на 10
User prompt
сделать каждому препятствию рандомную начальную скорость от 25 до 32
User prompt
сделать каждому препятствию рандомную начальную скорость от 20 до 32
User prompt
сделать каждому препятствию рандомную начальную скорость от 25 до 30
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); // Set speed to 20 in a random direction within 360 degrees var angle = Math.random() * Math.PI * 2; // Random angle in radians self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.move = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off walls if (self.x < 145 || self.x > 1903) { self.speedX *= -1; } if (self.y < 145 || self.y > 2587) { self.speedY *= -1; } }; }); // Obstacle2 class var Obstacle2 = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle2', { anchorX: 0.5, anchorY: 0.5 }); // Set speed to 20 in a random direction within 360 degrees var angle = Math.random() * Math.PI * 2; // Random angle in radians self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.move = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off walls if (self.x < 145 || self.x > 1903) { self.speedX *= -1; } if (self.y < 145 || self.y > 2587) { self.speedY *= -1; } }; }); // Obstacle3 class var Obstacle3 = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle3', { anchorX: 0.5, anchorY: 0.5 }); // Set speed to 20 in a random direction within 360 degrees var angle = Math.random() * Math.PI * 2; // Random angle in radians self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.move = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off walls if (self.x < 145 || self.x > 1903) { self.speedX *= -1; } if (self.y < 145 || self.y > 2587) { self.speedY *= -1; } }; }); // Obstacle4 class var Obstacle4 = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle4', { anchorX: 0.5, anchorY: 0.5 }); // Set speed to 20 in a random direction within 360 degrees var angle = Math.random() * Math.PI * 2; // Random angle in radians self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50; self.move = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off walls if (self.x < 145 || self.x > 1903) { self.speedX *= -1; } if (self.y < 145 || self.y > 2587) { self.speedY *= -1; } }; }); // Assets will be automatically created based on usage in the code. // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 33; self.move = function (direction) { if (direction === 'left' && self.x > 145) { self.x -= self.speed; } else if (direction === 'right' && self.x < 1903) { self.x += self.speed; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF // Init game with white background }); /**** * Game Code ****/ var obstacle3 = game.addChild(new Obstacle3()); obstacle3.x = obstacle3.width / 2 + 150; // Position at the left edge of the screen obstacle3.y = 2732 - obstacle3.height / 2 - 150; // Position at the bottom edge of the screen; var obstacle4 = game.addChild(new Obstacle4()); obstacle4.x = 2048 - obstacle4.width / 2 - 150; // Position at the right edge of the screen obstacle4.y = 2732 - obstacle4.height / 2 - 150; // Position at the bottom edge of the screen; LK.on('tick', function () { // Calculate the distance between the player and the target position var dx = targetPosition.x - player.x; var dy = targetPosition.y - player.y; var distance = Math.sqrt(dx * dx + dy * dy); // If the player is not already at the target position and the screen is being pressed if (isScreenPressed && distance > player.speed) { // Calculate the direction vector var directionX = dx / distance; var directionY = dy / distance; // Move the player towards the target position player.x += directionX * player.speed; player.y += directionY * player.speed; } // Check if the new position is within the screen boundaries if (player.x < 145) { player.x = 145; } else if (player.x > 1903) { player.x = 1903; } if (player.y < 145) { player.y = 145; } else if (player.y > 2587) { player.y = 2587; } // Move the obstacles obstacle.move(); obstacle2.move(); obstacle3.move(); obstacle4.move(); // Check if player intersects with any obstacle if (player.intersects(obstacle) || player.intersects(obstacle2) || player.intersects(obstacle3) || player.intersects(obstacle4)) { // Flash screen red for 1 second (1000ms) to show we are dead. LK.effects.flashScreen(0xff0000, 1000); // Save the player's score in decimal format LK.setScore(parseFloat(timer.toFixed(10))); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); } }); var player = game.addChild(new Player()); player.x = 2048 / 2; // Center horizontally player.y = 2732 / 2; // Center vertically var targetPosition = { x: player.x, y: player.y }; // Store the target position for the player var isScreenPressed = false; // Flag to track if the screen is being pressed game.on('down', function (obj) { isScreenPressed = true; // Set the flag to true when the screen is pressed }); game.on('move', function (obj) { if (isScreenPressed) { targetPosition = obj.event.getLocalPosition(game); // Set the target position to the cursor position if the screen is being pressed } }); game.on('up', function (obj) { isScreenPressed = false; // Set the flag to false when the screen is released targetPosition = { x: player.x, y: player.y }; // Set the target position to the player's current position }); // Add a timer in the top left corner var timerTxt = new Text2('0', { size: 70, fill: "#000000" }); timerTxt.x = -170; LK.gui.topRight.addChild(timerTxt); var timer = 0; var frameCount = 0; LK.on('tick', function () { frameCount++; if (frameCount > 1) { timer += 1 / 60; // increment timer by the time for one frame } timerTxt.setText(timer.toFixed(2)); // update the timer text to include hundredths of a second }); var obstacle = game.addChild(new Obstacle()); obstacle.x = 2048 - obstacle.width / 2 - 150; // Position at the right edge of the screen, 200 pixels away from the edge obstacle.y = obstacle.height / 2 + 150; // Position at the top edge of the screen, 200 pixels away from the edge; var obstacle2 = game.addChild(new Obstacle2()); obstacle2.x = obstacle2.width / 2 + 150; // Position at the left edge of the screen obstacle2.y = obstacle2.height / 2 + 150; // Position at the top edge of the screen
===================================================================
--- original.js
+++ change.js
@@ -9,10 +9,10 @@
anchorY: 0.5
});
// Set speed to 20 in a random direction within 360 degrees
var angle = Math.random() * Math.PI * 2; // Random angle in radians
- self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
- self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
+ self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
+ self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off walls
@@ -32,10 +32,10 @@
anchorY: 0.5
});
// Set speed to 20 in a random direction within 360 degrees
var angle = Math.random() * Math.PI * 2; // Random angle in radians
- self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
- self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
+ self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
+ self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off walls
@@ -55,10 +55,10 @@
anchorY: 0.5
});
// Set speed to 20 in a random direction within 360 degrees
var angle = Math.random() * Math.PI * 2; // Random angle in radians
- self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
- self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
+ self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
+ self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off walls
@@ -78,10 +78,10 @@
anchorY: 0.5
});
// Set speed to 20 in a random direction within 360 degrees
var angle = Math.random() * Math.PI * 2; // Random angle in radians
- self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
- self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + (timer > 3 ? 20 : 0);
+ self.speedX = Math.cos(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
+ self.speedY = Math.sin(angle) * (Math.random() * (32 - 25) + 25) + Math.floor(timer / 3) * 50;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
// Bounce off walls
квадрат со злым лицом.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
нужно закрасить тень за квадратом
квадрат с испуганным лицом. Белый. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
квадрат со злым лицом. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.