User prompt
при сталкновении самолета с потолком или полом game over
User prompt
при сталкновении со стеной самолет появляется с другой стороны стены
User prompt
менять направление движения на 2 градуса
User prompt
менять направление движения на 4 градуса
Code edit (1 edits merged)
Please save this source code
User prompt
менять направление движения не на 15 градусов, а на 1 градус
User prompt
после нажатия и удерживания на экран направление движения против часовой стрелке
User prompt
если происходит удерживание по экрану, то самолет продолжается поворачиваться
User prompt
после нажатия на экран, направление движения самолета меняется на 15 градусов
Initial prompt
planes wars
===================================================================
--- original.js
+++ change.js
@@ -1,118 +1,126 @@
-/****
+/****
* Classes
-****/
+****/
// Bullet class
var Bullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
- width: 10,
- height: 20,
- color: 0xffffff,
- shape: 'box'
- });
- self.speed = -10;
- // Move bullet
- self.move = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ width: 10,
+ height: 20,
+ color: 0xffffff,
+ shape: 'box'
+ });
+ self.speed = -10;
+ // Move bullet
+ self.move = function () {
+ self.y += self.speed;
+ };
});
// Assets are automatically created based on usage in the code.
// Plane class
var Plane = Container.expand(function () {
- var self = Container.call(this);
- // Initialize plane with a shape asset
- var planeGraphics = self.attachAsset('plane', {
- width: 60,
- height: 60,
- color: 0xff0000,
- // Default red, will be overridden
- shape: 'ellipse'
- });
- self.speedX = 0;
- self.speedY = 0;
- // Method to update plane position
- self.update = function () {
- self.x += self.speedX;
- self.y += self.speedY;
- // Keep the plane within the game boundaries
- if (self.x < 0 || self.x > 2048) self.speedX *= -1;
- if (self.y < 0 || self.y > 2732) self.speedY *= -1;
- };
- // Method to shoot a bullet
- self.shoot = function () {
- var bullet = new Bullet();
- bullet.x = self.x;
- bullet.y = self.y;
- bullets.push(bullet);
- game.addChild(bullet);
- };
+ var self = Container.call(this);
+ // Initialize plane with a shape asset
+ var planeGraphics = self.attachAsset('plane', {
+ width: 60,
+ height: 60,
+ color: 0xff0000,
+ // Default red, will be overridden
+ shape: 'ellipse'
+ });
+ self.speedX = 0;
+ self.speedY = 0;
+ // Method to update plane position
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ // Keep the plane within the game boundaries
+ if (self.x < 0 || self.x > 2048) {
+ self.speedX *= -1;
+ }
+ if (self.y < 0 || self.y > 2732) {
+ self.speedY *= -1;
+ }
+ };
+ // Method to shoot a bullet
+ self.shoot = function () {
+ var bullet = new Bullet();
+ bullet.x = self.x;
+ bullet.y = self.y;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var bullets = []; // Global array to keep track of bullets
// Create two planes
var plane1 = new Plane();
plane1.x = 200;
plane1.y = 200;
plane1.speedX = 5;
plane1.speedY = 3;
plane1.attachAsset('plane', {
- color: 0x0000ff
+ color: 0x0000ff
}); // Blue color for plane1
var plane2 = new Plane();
plane2.x = 1848; // Start from the opposite side
plane2.y = 2532;
plane2.speedX = -5;
plane2.speedY = -3;
plane2.attachAsset('plane', {
- color: 0xff0000
+ color: 0xff0000
}); // Red color for plane2
// Add planes to the game
game.addChild(plane1);
game.addChild(plane2);
// Set up game tick
LK.on('tick', function () {
- plane1.update();
- plane2.update();
- // Planes shoot bullets periodically
- if (LK.ticks % 60 == 0) {
- plane1.shoot();
- plane2.shoot();
- }
- // Update and check bullets
- for (var i = bullets.length - 1; i >= 0; i--) {
- bullets[i].move();
- // Check for bullet collision with planes
- if (bullets[i].intersects(plane1) || bullets[i].intersects(plane2)) {
- // For simplicity, just remove the bullet on collision
- bullets[i].destroy();
- bullets.splice(i, 1);
- } else if (bullets[i].y < -50 || bullets[i].y > 2782) {
- // Remove off-screen bullets
- bullets[i].destroy();
- bullets.splice(i, 1);
- }
- }
+ plane1.update();
+ plane2.update();
+ // Planes shoot bullets periodically
+ if (LK.ticks % 60 == 0) {
+ plane1.shoot();
+ plane2.shoot();
+ }
+ // Update and check bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].move();
+ // Check for bullet collision with planes
+ if (bullets[i].intersects(plane1) || bullets[i].intersects(plane2)) {
+ // For simplicity, just remove the bullet on collision
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ } else if (bullets[i].y < -50 || bullets[i].y > 2782) {
+ // Remove off-screen bullets
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ }
+ }
});
// Simple touch controls to change plane directions
game.on('down', function (obj) {
- var pos = obj.event.getLocalPosition(game);
- // If touch is on the left half of the screen, change plane1 direction
- if (pos.x < 1024) {
- plane1.speedX *= -1;
- plane1.speedY *= -1;
- } else {
- // If touch is on the right half, change plane2 direction
- plane2.speedX *= -1;
- plane2.speedY *= -1;
- }
+ var pos = obj.event.getLocalPosition(game);
+ // If touch is on the left half of the screen, change plane1 direction
+ if (pos.x < 1024) {
+ var angle = Math.atan2(plane1.speedY, plane1.speedX);
+ angle += Math.PI / 12; // Add 15 degrees (in radians)
+ plane1.speedX = Math.cos(angle) * 5;
+ plane1.speedY = Math.sin(angle) * 5;
+ } else {
+ // If touch is on the right half, change plane2 direction
+ var angle = Math.atan2(plane2.speedY, plane2.speedX);
+ angle += Math.PI / 12; // Add 15 degrees (in radians)
+ plane2.speedX = Math.cos(angle) * 5;
+ plane2.speedY = Math.sin(angle) * 5;
+ }
});
\ No newline at end of file
снаряд от пушки. 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.