Code edit (2 edits merged)
Please save this source code
User prompt
Создать cannon2 по аналогии с: var cannon = new Cannon(); cannon.x = -100; // Position at the bottom left of the screen cannon.y = 2660; game.addChild(cannon);
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cannon2.x')' in or related to this line: 'if (cannon2.x > 2048 - 100) {' Line Number: 275
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cannon2.x')' in or related to this line: 'if (cannon2.x > 2048 - 100) {' Line Number: 275
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'cannon2.x')' in or related to this line: 'if (cannon2.x > 2048 - 100) {' Line Number: 275
User prompt
Исправить ошибку, когда cannon2 не видно за задним фоном
User prompt
Добавить cannon 2 в правой нижней части экрана
Code edit (3 edits merged)
Please save this source code
User prompt
Пушка появляется слева за экраном и двигается на расстояние x = 100
User prompt
Оружие появляется слева за экраном и двигается направо. Останавливаются на расстоянии по x 100
Code edit (1 edits merged)
Please save this source code
User prompt
Добавить cannon в нижней левой части экрана
User prompt
При столкновении с противником добавить флешскрин красный
User prompt
При смерте, добавить флешскрин красный
User prompt
Пересечение игрока и противника проверяться по координатам 100 на 100
User prompt
Please fix the bug: 'TypeError: enemyPlanes[i].getAsset is not a function. (In 'enemyPlanes[i].getAsset('enemy')', 'enemyPlanes[i].getAsset' is undefined)' in or related to this line: 'if (plane1.intersects(enemyPlanes[i].getAsset('enemy'))) {' Line Number: 247
User prompt
Исправить ошибку, когда игрок и противник не пересеклись, но наступил конец игры
User prompt
Please fix the bug: 'TypeError: enemyPlanes[i].getAsset is not a function. (In 'enemyPlanes[i].getAsset('enemy')', 'enemyPlanes[i].getAsset' is undefined)' in or related to this line: 'if (plane1.intersects(enemyPlanes[i].getAsset('enemy'))) {' Line Number: 247
User prompt
Пересечение игрока по изображению, а не объекту
User prompt
Про пересечении игрока и противника смерть
User prompt
Удалить выстрелы
User prompt
Fix the issue where the bullet stays at its spawn point
User prompt
Fix the issue where the bullet stays at its spawn point
User prompt
Fix the issue where the bullet stays at its spawn point
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 = 8;
// Move bullet
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
var index = bullets.indexOf(self);
if (index > -1) {
bullets.splice(index, 1);
}
}
};
});
// EnemyPlane class
var EnemyPlane = Container.expand(function () {
var self = Container.call(this);
var enemyPlaneGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -6;
self.speedY = 0;
// Update enemy plane position
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Add bullet shooting functionality
if (LK.ticks % 240 == 0) {
// Shoot a bullet every second
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.speedX = self.speedX * 2; // Bullet moves in the same direction as the enemy plane and twice as fast
bullet.speedY = self.speedY;
game.addChild(bullet);
bullets.push(bullet);
}
};
});
// EnemyPlaneLeft class
var EnemyPlaneLeft = Container.expand(function () {
var self = Container.call(this);
var enemyPlaneGraphics = self.attachAsset('Enemyleft', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 6;
self.speedY = 0;
// Update enemy plane position
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Add bullet shooting functionality
if (LK.ticks % 240 == 0) {
// Shoot a bullet every second
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.speedX = self.speedX * 2; // Bullet moves in the same direction as the enemy plane and twice as fast
bullet.speedY = self.speedY;
game.addChild(bullet);
bullets.push(bullet);
}
};
});
// 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;
}
};
// Player's plane no longer shoots bullets
self.shoot = function () {};
});
/****
* 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 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 enemyPlanes = []; // Global array to keep track of enemy planes
var enemyPlane; // Global variable to keep track of the enemy plane
// Create a player plane
var plane1 = new Plane1();
plane1.x = 150; // Moved 50 units to the right
plane1.y = 2750 - plane1.height; // Bottom of the screen
game.addChild(plane1);
// Create the rest of the enemy planes every 2 seconds for the first 7 seconds
var enemySpawnTimer = LK.setInterval(function () {
enemyPlane = new EnemyPlane();
enemyPlane.x = 2150;
enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
game.addChild(enemyPlane);
enemyPlanes.push(enemyPlane);
var enemyPlaneLeft = new EnemyPlaneLeft();
enemyPlaneLeft.x = -100;
enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
game.addChild(enemyPlaneLeft);
enemyPlanes.push(enemyPlaneLeft);
}, 1500);
// After 7 seconds, change the enemy spawn interval to 1 every 1.3 seconds
LK.setTimeout(function () {
LK.clearInterval(enemySpawnTimer);
enemySpawnTimer = LK.setInterval(function () {
enemyPlane = new EnemyPlane();
enemyPlane.x = 2150;
enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
game.addChild(enemyPlane);
enemyPlanes.push(enemyPlane);
var enemyPlaneLeft = new EnemyPlaneLeft();
enemyPlaneLeft.x = -100;
enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
game.addChild(enemyPlaneLeft);
enemyPlanes.push(enemyPlaneLeft);
}, 1300);
}, 7000);
// After 14 seconds, change the enemy spawn interval to 1 every second
LK.setTimeout(function () {
LK.clearInterval(enemySpawnTimer);
enemySpawnTimer = LK.setInterval(function () {
enemyPlane = new EnemyPlane();
enemyPlane.x = 2150;
enemyPlane.y = 100 + Math.random() * (2732 - enemyPlane.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
game.addChild(enemyPlane);
enemyPlanes.push(enemyPlane);
var enemyPlaneLeft = new EnemyPlaneLeft();
enemyPlaneLeft.x = -100;
enemyPlaneLeft.y = 100 + Math.random() * (2732 - enemyPlaneLeft.height - 100); // Random y-coordinate between 100 and 2732 minus the height of the enemy plane
game.addChild(enemyPlaneLeft);
enemyPlanes.push(enemyPlaneLeft);
}, 1000);
}, 14000);
// Set up game tick
LK.on('tick', function () {
plane1.update();
// Update all enemy planes
for (var i = 0; i < enemyPlanes.length; i++) {
enemyPlanes[i].update();
}
// EnemyBot removed, no initialization here
// Removed enemyBot.stateTime increment
// EnemyBot related code removed
// Player's plane no longer shoots bullets
// Player's plane no longer shoots bullets, so no need to update bullets
});
// 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
}
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
}
// Check if the plane crosses the side boundaries of the screen, touches the top or bottom of the screen, or collides with the health_bar
if (plane1.x <= 70 || plane1.x >= 2170 - plane1.width || plane1.y <= 70 || plane1.y >= 2752 - plane1.height) {
// 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.