Code edit (4 edits merged)
Please save this source code
User prompt
переместить респаун игрока на 50 пикселей вверх
Code edit (9 edits merged)
Please save this source code
User prompt
исправить ошибку, когда при возраждении противник начинает набирать скорость, а не едет со скоростью 7
User prompt
при возраждении скорость противника равна7
Code edit (1 edits merged)
Please save this source code
User prompt
после смерти противника, игрок появляется на месте своего возрождения через 0.5 секунды
User prompt
при возраждении противник увеличивается до своего размера за 0.1 секунды
User prompt
Please fix the bug: 'TypeError: car.followPlayer is not a function' in or related to this line: 'car.followPlayer(cars[0]); // Assume the player car is the first car in the array' Line Number: 197
User prompt
после пересечения радиуса противником, он в течении секунды двигает подальше от центра игры и перестает преследование на 1 секунду
User prompt
после пересечения радиуса противником, он в течении секунды двигает подальше от центра игры
Code edit (1 edits merged)
Please save this source code
User prompt
после пересечения радиуса противник на 1.2 секунды перестает преследовать игрока
User prompt
после пересечения радиуса противник на секунду перестает преследовать игрока
Code edit (1 edits merged)
Please save this source code
User prompt
после смерти противника, противник и игрок остаются на месте, на котором были перед смертью противника на 2 секунды
User prompt
исправить ошибку, когда противник после пересечения радиуса начинает движение сразу, а не останавливается на 2 секунды
User prompt
после смерти противника, игрок и противник останавливаются на 2 секунды, после 2х секунды появляются на местах возраждения
User prompt
исправить ошибку, когда противник пересек радиус 950 и на секунду не остановился
User prompt
исправить ошибку, когда противник пересекает радиус 950 и продолжает ехать дальше
User prompt
исправить ошибку, когда за одно пересечение противника радиуса 950 прибавилось больше 1 очка
User prompt
если противник пересек радиус 950, то прибавлять одно очко в SCORE
User prompt
исправить ошибку, когда прибавляется не одно очко при смерти противника, а сразу несколько
Code edit (1 edits merged)
Please save this source code
User prompt
при возрождении противника размер модельки противника равен x=200 y=150
/****
* Classes
****/
// Assets will be automatically created based on usage in the code.
// Car class
var Car = Container.expand(function () {
var self = Container.call(this);
// Attach a car asset
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.previousTouchPosition = null;
self.speedX = 0;
self.speedY = 0;
// Move car based on its speed
self.move = function () {
if (self.slidingDuration > 0) {
self.x += self.speedX;
self.y += self.speedY;
self.slidingDuration--;
if (self.slidingDuration === 0) {
self.speedX = Math.sin(self.rotation) * 7;
self.speedY = -Math.cos(self.rotation) * 7;
}
} else {
self.x += self.speedX;
self.y += self.speedY;
}
};
// Prevent the car from moving in the opposite direction when it hits the wall
self.checkBounds = function () {
if (self.x < 0) {
self.x += 200;
} else if (self.x > 2048) {
self.x -= 200;
}
if (self.y < 0) {
self.y += 200;
} else if (self.y > 2732) {
self.y -= 200;
}
};
self.slidingDuration = 0;
self.setDirection = function (direction) {
if (direction === 'left') {
self.rotation -= 0.07;
self.speedX += Math.sin(self.rotation) * 0.07;
self.speedY += -Math.cos(self.rotation) * 0.07;
self.slidingDuration = 20; // Set sliding duration to 0.5 second (30 frames)
} else if (direction === 'right') {
self.rotation += 0.07;
self.speedX += Math.sin(self.rotation) * 0.07;
self.speedY += -Math.cos(self.rotation) * 0.07;
self.slidingDuration = 20; // Set sliding duration to 0.5 second (30 frames)
}
// Limit the speed to prevent the car from sliding too much
if (self.slidingDuration > 0) {
self.speedX = Math.min(Math.max(self.speedX, -7), 7);
self.speedY = Math.min(Math.max(self.speedY, -7), 7);
self.slidingDuration--;
} else {
self.speedX = Math.sin(self.rotation) * (self.slidingDuration > 4 && self.slidingDuration <= 7 ? 7 : 4);
self.speedY = -Math.cos(self.rotation) * (self.slidingDuration > 4 && self.slidingDuration <= 7 ? 7 : 4);
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
// Attach an enemy asset
var enemyGraphics = self.attachAsset('enemy1', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
// Move enemy based on its speed
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
// Prevent the enemy from moving in the opposite direction when it hits the wall
self.checkBounds = function () {
if (self.x < 0) {
self.x += 200;
} else if (self.x > 2048) {
self.x -= 200;
}
if (self.y < 0) {
self.y += 200;
} else if (self.y > 2732) {
self.y -= 200;
}
};
self.followPlayer = function (player) {
// Calculate the direction vector from the enemy to the player
var dx = player.x - self.x;
var dy = player.y - self.y;
// Normalize the direction vector
var length = Math.sqrt(dx * dx + dy * dy);
dx /= length;
dy /= length;
// Set the enemy's speed to move towards the player
// Add sliding behavior to the enemy car
self.speedX += dx * 0.05;
self.speedY += dy * 0.05;
if (self.slidingDuration > 0) {
self.slidingDuration--;
if (self.slidingDuration === 0) {
// Calculate the direction vector from the enemy to the player
var dx = player.x - self.x;
var dy = player.y - self.y;
// Normalize the direction vector
var length = Math.sqrt(dx * dx + dy * dy);
dx /= length;
dy /= length;
// Set the enemy's speed to always be 7
self.speedX = dx * (self.slidingDuration > 5 && self.slidingDuration <= 7 ? 7 : 5);
self.speedY = dy * (self.slidingDuration > 5 && self.slidingDuration <= 7 ? 7 : 5);
}
} else {
self.slidingDuration = 90; // Set sliding duration to 2 seconds (120 frames)
}
// Calculate the angle of the direction vector
var angle = Math.atan2(dy, dx);
// Rotate the enemy car to face the player and adjust by -90 degrees
self.rotation = angle - Math.PI / 2;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFF // Init game with white background
});
/****
* Game Code
****/
// Global variables
var cars = [];
// Create a single car
var car = new Car();
car.x = 2048 / 2; // Center of the screen
car.y = 2280; // Bottom of the screen
car.speedX = 0;
car.speedY = -7;
cars.push(car);
game.addChildAt(car, game.children.length);
// Create an enemy car
var enemy = new Enemy();
enemy.x = 2048 / 2; // Center of the screen
enemy.y = 450; // Top of the screen
enemy.speedX = 0;
enemy.speedY = 7;
cars.push(enemy);
game.addChildAt(enemy, game.children.length);
// Create a background for the game
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChildAt(background, 0);
// Create a circle in the center of the screen
var centerCircle = LK.getAsset('Circle', {
anchorX: 0.5,
// Center anchor x-coordinate
anchorY: 0.5,
// Center anchor y-coordinate
x: 2048 / 2,
// Center of the screen
y: 2732 / 2 // Center of the screen
});
game.addChildAt(centerCircle, 1);
// Handle game logic on each tick
LK.on('tick', function () {
cars.forEach(function (car) {
car.move();
car.checkBounds();
if (car === enemy) {
if (LK.ticks > 90) {
// Delay of 1.5 seconds (60 ticks per second)
car.followPlayer(cars[0]); // Assume the player car is the first car in the array
}
}
// Check for collisions with other cars
cars.forEach(function (otherCar) {
if (car !== otherCar) {
// Calculate the distance between the centers of the two cars
var dx = car.x - otherCar.x;
var dy = car.y - otherCar.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check if the distance is less than the sum of the radii of the two cars
if (distance < car.width / 2 + otherCar.width / 2) {
// On collision, move both cars 200 pixels back in the direction opposite to the point of intersection
var moveDistance = 60;
var moveStep = moveDistance / 10; // 60 frames for 1 second of smooth movement
var moveX = dx / distance * moveStep;
var moveY = dy / distance * moveStep;
var moveCounter = 0;
var moveInterval = LK.setInterval(function () {
car.x += moveX;
car.y += moveY;
otherCar.x -= moveX;
otherCar.y -= moveY;
moveCounter++;
if (moveCounter >= 10) {
LK.clearInterval(moveInterval);
}
}, 1000 / 60); // 60 FPS
}
}
});
// Check if the car is outside the circle
var distanceFromCenter = Math.sqrt(Math.pow(car.x - 2048 / 2, 2) + Math.pow(car.y - 2732 / 2, 2));
if (distanceFromCenter > 950 && car === enemy) {
// Shrink enemy to 1x1 pixel over 1 second upon defeat
var shrinkDuration = 60; // 1 second at 60 FPS
var originalWidth = car.width;
var originalHeight = car.height;
var shrinkInterval = LK.setInterval(function () {
car.width = Math.max(1, car.width - (originalWidth - 1) / shrinkDuration);
car.height = Math.max(1, car.height - (originalHeight - 1) / shrinkDuration);
shrinkDuration--;
if (shrinkDuration <= 0) {
LK.clearInterval(shrinkInterval);
// Reset enemy position to spawn point
car.x = 2048 / 2; // Center of the screen
car.y = 450; // Top of the screen
car.speedX = 0;
car.speedY = 7;
// Gradually increase enemy size to original dimensions
var growDuration = 60; // 1 second at 60 FPS
var currentWidth = car.width;
var currentHeight = car.height;
var widthIncrement = (originalWidth - currentWidth) / growDuration;
var heightIncrement = (originalHeight - currentHeight) / growDuration;
var growInterval = LK.setInterval(function () {
car.width += widthIncrement;
car.height += heightIncrement;
growDuration--;
if (growDuration <= 0) {
LK.clearInterval(growInterval);
car.width = 200;
car.height = 150;
}
}, 1000 / 60); // 60 FPS
}
}, 1000 / 60); // 60 FPS
// Reset player position to spawn point
cars[0].x = 2048 / 2; // Center of the screen
cars[0].y = 2280; // Bottom of the screen
// Make player move vertically upwards
cars[0].speedX = 0;
cars[0].speedY = -7;
// Reset player's rotation
cars[0].rotation = 0;
// Increment score by 1
LK.setScore(LK.getScore() + 1);
if (typeof localStorage !== 'undefined') {
localStorage.setItem('score', LK.getScore());
}
// Update score text
scoreTxt.setText(LK.getScore());
} else if (distanceFromCenter > 1970) {
LK.showGameOver();
}
});
});
// Create a score display at the top right corner of the screen
var score = typeof localStorage !== 'undefined' ? localStorage.getItem('score') || '0' : '0';
var scoreTxt = new Text2(score, {
size: 100,
fill: "#000000"
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
// Add touch event listener to the game
var turnInterval;
var lastTouchPosition;
var isTouching = false; // Add a flag to check if the screen is being touched
var isOutside = false; // Add a flag to check if the mouse is outside the game
game.on('down', function (obj) {
// Get the position of the touch
var touchPosition = obj.event.getLocalPosition(game);
// Store the initial touch position
car.initialTouchPosition = touchPosition;
// Store the last touch position
lastTouchPosition = touchPosition;
isTouching = true; // Set the flag to true when the screen is being touched
isOutside = false; // Set the flag to false when the mouse enters the game
});
game.on('move', function (obj) {
// Get the position of the touch
var touchPosition = obj.event.getLocalPosition(game);
// Update the last touch position
lastTouchPosition = touchPosition;
// If there is a touch event and the last touch position is to the left of the initial touch position, turn the car to the left
if (!isOutside && isTouching && lastTouchPosition && car.initialTouchPosition) {
if (lastTouchPosition.x < car.initialTouchPosition.x) {
car.setDirection('left');
} else if (lastTouchPosition.x > car.initialTouchPosition.x) {
car.setDirection('right');
}
// Update the initial touch position
car.initialTouchPosition = lastTouchPosition;
} else if (isTouching && !isOutside) {
// If there is no touch event, the car moves straight
car.setDirection('straight');
}
});
game.on('up', function (obj) {
// Reset the last touch position when the touch is released
lastTouchPosition = null;
isTouching = false; // Set the flag to false when the touch is released
isOutside = true; // Set the flag to true when the mouse leaves the game
});
Лава мультяшная вид сверху плоская. Single Game Texture. In-Game asset. 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.
шины на асфальте после торможения для игры. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.