User prompt
Please fix the bug: 'ReferenceError: Can't find variable: enemyBot' in or related to this line: 'enemyBot.stateTime++;' Line Number: 175
User prompt
Удалить enemybotw
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: enemyBot' in or related to this line: 'enemyBot.stateTime++;' Line Number: 215
User prompt
Удалить противника
User prompt
Противник может лететь только по направлению левой части картинки если нужно изменить маршрут , то движение противника также происходит от левой части картинки
User prompt
Изменить направление с дула на противоположную часть
User prompt
Противник может лететь только по направлению дула, если нужно изменить маршрут , то движение противника также происходит от дула
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: angleDifference' in or related to this line: 'if (angleDifference > 0) {' Line Number: 243
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: angleDifference' in or related to this line: 'if (angleDifference > 0) {' Line Number: 256
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: angleDifference' in or related to this line: 'if (angleDifference > 0) {' Line Number: 258
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: angleDifference' in or related to this line: 'if (angleDifference > 0) {' Line Number: 263
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: angleDifference' in or related to this line: 'if (angleDifference > 0) {' Line Number: 261
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: angleDifference' in or related to this line: 'if (angleDifference > 0) {' Line Number: 258
User prompt
если игрок пересек одну из стен и появился на другой стороне, то противник не ищет кратчайший путь, ему нужно продолжать движение вперед и развернуться по дуге с радиусом разворота 1 градус
User prompt
исправить ошибку, когда при самолете еще не пересеклись верхними частями картинки, а наступи game over
User prompt
исправить ошибку, когда при нахождении кратчайшего пути противник полностью меняет траекторию движения
User prompt
противник не может лететь левой частью картинки по направлению движения
User prompt
если кратчайший путь требует изменение траектории движения больше чем на 20 градусов, то переставать преследовать
User prompt
противник может преследовать игрока, только двигаясь правой частью объекта
User prompt
противник может преследовать игрока, только двигаясь правой частью картинки вперед
User prompt
противник преследует игрока, только если расстояние между ними не больше 1000, иначе летит случайном направлении
User prompt
противник может пролетать сквозь стены и появляться на другой стороне на этой же высоте
User prompt
противник может пролетать сквозь стены и появляться на другой стороне
User prompt
остановить игрока, дать ручное управление противнику
User prompt
исправить ошибку, когда противник выбирая короткий путь меняет направление с плюс на минус
/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
width: 15,
height: 15,
color: 0xffffff,
shape: 'box'
});
self.speed = -30;
// Move bullet
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
// EnemyBot class
var EnemyBot = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
// EnemyBot always chases the player
self.update = function () {
// Calculate direction towards the player's plane
var dx = plane1.x - self.x;
var dy = plane1.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.speedX = dx / distance * 5;
self.speedY = dy / distance * 5;
}
self.x += self.speedX;
self.y += self.speedY;
// Prevent enemy from moving out of bounds
// Check if the player has crossed the screen boundary
if (plane1.x < 0 || plane1.x > 2048) {
// Calculate the angle to the player's new position considering screen wrap
var targetX = plane1.x < 0 ? 2048 : 0;
var targetY = plane1.y;
var angleToPlayer = Math.atan2(targetY - self.y, targetX - self.x);
// Determine the correct direction to rotate based on shortest path
var currentAngle = enemyGraphics.rotation;
var angleDifference = angleToPlayer - currentAngle;
angleDifference -= Math.floor((angleDifference + Math.PI) / (2 * Math.PI)) * (2 * Math.PI);
var angleIncrement = angleDifference > 0 ? Math.PI / 180 : -Math.PI / 180;
// Calculate circular rotation path
var radius = 100; // Radius of the circular path
var circleCenterX = plane1.x < 0 ? 2048 - radius : radius; // Center of the circle based on player's exit point
var circleCenterY = self.y; // Keep the same Y to create a horizontal circle
// Update enemy's position along the circular path
var newAngle = currentAngle + angleIncrement;
self.x = circleCenterX + radius * Math.cos(newAngle);
self.y = circleCenterY + radius * Math.sin(newAngle);
// Update enemy's rotation to face towards the player's new position
enemyGraphics.rotation = newAngle;
}
if (self.y < 0) {
self.y = 0;
self.speedY = 0;
} else if (self.y > 2752 - self.height) {
self.y = 2752 - self.height;
self.speedY = 0;
}
// Rotate the enemy image smoothly towards the direction of movement
var targetAngle = Math.atan2(self.speedY, self.speedX);
var currentAngle = enemyGraphics.rotation;
// Calculate shortest path to target angle
var angleDifference = targetAngle - currentAngle;
angleDifference -= Math.floor((angleDifference + Math.PI) / (2 * Math.PI)) * (2 * Math.PI);
// Rotate smoothly towards the target angle
if (angleDifference > 0) {
enemyGraphics.rotation -= Math.min(angleDifference, Math.PI / 180); // Rotate counter-clockwise by 1 degree
} else {
enemyGraphics.rotation -= Math.max(angleDifference, -Math.PI / 180); // Rotate clockwise by 1 degree
}
};
});
// Plane1 class
var Plane1 = Container.expand(function () {
var self = Container.call(this);
var planeGraphics = self.attachAsset('plane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 7;
self.speedY = 0;
// Update plane position
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Check if the plane has crossed the screen boundary
if (self.x < 0) {
self.x = 2048;
} else if (self.x > 2048) {
self.x = 0;
}
// Prevent the plane from crossing the floor and ceiling
if (self.y < 0) {
self.y = 0;
self.speedY = 0;
} else if (self.y > 2752 - self.height) {
self.y = 2752 - self.height;
self.speedY = 0;
}
};
// Plane shoots a bullet
self.shoot = function () {
var bullet = new Bullet();
// Set bullet position to the front of the plane
var planeFrontX = self.x + self.width / 2 * Math.cos(self.rotation);
var planeFrontY = self.y + self.width / 2 * Math.sin(self.rotation);
bullet.x = planeFrontX;
bullet.y = planeFrontY;
// Set bullet speed to twice the plane's speed in the direction of the plane
bullet.speedX = 2 * self.speedX;
bullet.speedY = 2 * self.speedY;
bullets.push(bullet);
game.addChild(bullet);
};
});
/****
* Initialize Game
****/
// Assets are automatically created based on usage in the code.
var game = new LK.Game({
backgroundColor: 0xffffff // Init game with white background
});
/****
* Game Code
****/
// Add health_bar to the top of the game
var healthBar = LK.gui.top.attachAsset('health_bar', {
anchorX: 0.5,
anchorY: 0
});
healthBar.x = 2048 / 8;
healthBar.y = -20;
// Add first heart to the health_bar
var heart1 = healthBar.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart1.x = 395;
heart1.y = 90;
// Ensure the heart is always in the foreground
if (healthBar.children.length > 0) {
healthBar.setChildIndex(heart1, healthBar.children.length - 1);
} else {
healthBar.addChild(heart1);
}
// Add second heart to the health_bar
var heart2 = healthBar.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart2.x = 280;
heart2.y = 90;
// Ensure the heart is always in the foreground
if (healthBar.children.length > 0) {
healthBar.setChildIndex(heart2, healthBar.children.length - 1);
} else {
healthBar.addChild(heart2);
}
// Add third heart to the health_bar
var heart3 = healthBar.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart3.x = 165;
heart3.y = 90;
// Ensure the heart is always in the foreground
if (healthBar.children.length > 0) {
healthBar.setChildIndex(heart3, healthBar.children.length - 1);
} else {
healthBar.addChild(heart3);
}
// Add death image to the game at position X=500, Y=100
var deathImage = game.attachAsset('death', {
anchorX: 0.5,
anchorY: 0.5
});
deathImage.x = 300;
deathImage.y = 300;
// Ensure the death image is always in the foreground
if (game.children.length > 0) {
game.setChildIndex(deathImage, game.children.length - 1);
} else {
game.addChild(deathImage);
}
// Add background2 to the middle of the game
var background2 = game.attachAsset('background2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
});
background2.x = 2175 / 2;
background2.y = 2620 / 2;
// Add background to the bottom of the game
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 1,
scaleX: 1,
scaleY: 1
});
background.y = 2732;
var bullets = []; // Global array to keep track of bullets
var bullets = []; // Global array to keep track of bullets
// Create a plane
var plane1 = new Plane1();
plane1.x = 100;
plane1.y = 2750 - plane1.height; // Bottom of the screen
game.addChild(plane1);
// Create an enemy bot
var enemyBot = new EnemyBot();
enemyBot.x = 1900;
enemyBot.y = 2750 - enemyBot.height; // Bottom of the screen
game.addChild(enemyBot);
// Add a variable to track the enemy's state and time since state change
enemyBot.state = 'chasing';
enemyBot.stateTime = 0;
// Create a plane
// Set up game tick
LK.on('tick', function () {
plane1.update();
// Update the enemy's state and behavior based on the state
enemyBot.stateTime++;
if (enemyBot.state === 'chasing') {
if (enemyBot.stateTime >= 300) {
// 5 seconds * 60 FPS
enemyBot.state = 'wandering';
enemyBot.stateTime = 0;
// Set the enemy's speed to a random direction
var angle = Math.random() * 2 * Math.PI;
enemyBot.speedX = Math.cos(angle) * 5;
enemyBot.speedY = Math.sin(angle) * 5;
// Rotate smoothly towards the target angle
if (angleDifference > 0) {
enemyGraphics.rotation += Math.min(angleDifference, Math.PI / 180 * 5); // Rotate counter-clockwise by 5 degrees
} else {
enemyGraphics.rotation += Math.max(angleDifference, -Math.PI / 180 * 5); // Rotate clockwise by 5 degrees
}
} else {
// Follow the player's plane
var dx = plane1.x - enemyBot.x;
var dy = plane1.y - enemyBot.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
enemyBot.speedX = dx / distance * 5;
enemyBot.speedY = dy / distance * 5;
}
}
} else if (enemyBot.state === 'wandering') {
if (enemyBot.stateTime >= 180) {
// 3 seconds * 60 FPS
enemyBot.state = 'chasing';
enemyBot.stateTime = 0;
} else if (enemyBot.stateTime % 60 == 0) {
// every second
// Change direction randomly within +- 15 degrees
var currentAngle = Math.atan2(enemyBot.speedY, enemyBot.speedX);
var newAngle = currentAngle + (Math.random() - 0.5) * Math.PI / 6; // random angle within +- 15 degrees
enemyBot.speedX = Math.cos(newAngle) * 5;
enemyBot.speedY = Math.sin(newAngle) * 5;
}
}
enemyBot.update();
// Plane shoots a bullet every 0.8 seconds
if (LK.ticks % 48 == 0) {
plane1.shoot();
}
// Update and check bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].move();
// Remove off-screen bullets
if (bullets[i].x > 2048 || bullets[i].y > 2732) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
});
// Flags to track if the screen is being touched
var isTouchingLeft = false;
var isTouchingRight = false;
// Change enemy direction when the screen is touched
var initialTouchPosition = null;
game.on('down', function (obj) {
initialTouchPosition = obj.event.getLocalPosition(game);
});
game.on('move', function (obj) {
if (initialTouchPosition) {
var currentTouchPosition = obj.event.getLocalPosition(game);
var swipeDirection = currentTouchPosition.x - initialTouchPosition.x;
if (swipeDirection < 0) {
isTouchingLeft = true;
isTouchingRight = false;
} else if (swipeDirection > 0) {
isTouchingRight = true;
isTouchingLeft = false;
}
}
});
// Stop changing enemy direction when the screen is no longer being touched
game.on('up', function (obj) {
isTouchingLeft = false;
isTouchingRight = false;
initialTouchPosition = null;
});
// In the game tick, change plane direction while the screen is being touched
LK.on('tick', function () {
if (isTouchingLeft) {
var angle = Math.atan2(plane1.speedY, plane1.speedX);
angle -= Math.PI / 60; // Subtract 1.5 degrees (in radians) for counter-clockwise rotation
plane1.speedX = Math.cos(angle) * 7;
plane1.speedY = Math.sin(angle) * 7;
plane1.rotation -= Math.PI / 60; // Rotate the plane counter-clockwise
// Enemy rotation mechanics disabled on screen touch
}
if (isTouchingRight && LK.ticks > 78) {
var angle = Math.atan2(plane1.speedY, plane1.speedX);
angle += Math.PI / 60; // Add 1.5 degrees (in radians) for clockwise rotation
plane1.speedX = Math.cos(angle) * 7;
plane1.speedY = Math.sin(angle) * 7;
plane1.rotation += Math.PI / 60; // Rotate the plane clockwise
// Enemy rotation mechanics disabled on screen touch
}
// Check if the plane touches the top or bottom of the screen, collides with the health_bar, or collides with the enemy bot
// Also check if the images intersect within x=200, y=100
if (plane1.y <= 0 || plane1.y >= 2752 - plane1.height || plane1.intersects(healthBar) || Math.sqrt(Math.pow(plane1.x - enemyBot.x, 2) + Math.pow(plane1.y - enemyBot.y, 2)) <= enemyBot.width / 2 + plane1.width / 2 && Math.abs(plane1.x - enemyBot.x) <= 200 && Math.abs(plane1.y - enemyBot.y) <= 90) {
// Check for collision based on visible image, not transparent layer
if (plane1.alpha !== 0 && enemyBot.alpha !== 0 && plane1.intersects(enemyBot)) {
// Trigger game over
LK.showGameOver();
}
}
// Check if the plane touches the bottom of the screen or collides with the health_bar
if (plane1.y >= 2752 - plane1.height || plane1.intersects(healthBar)) {
// Trigger game over
LK.showGameOver();
}
});
снаряд от пушки. 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.
Нажатие по экрану. Палец. Мультяшный. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.