/****
* Classes
****/
// Define a class for Bullets
var Bullet = Container.expand(function () {
  var self = Container.call(this);
  var bulletGraphics = self.attachAsset('bullet', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = -15;
  self.update = function () {
    self.y += self.speed;
    if (self.y < 0) {
      self.destroy();
    }
  };
});
// Define a class for Enemy Ships
var EnemyShip = Container.expand(function () {
  var self = Container.call(this);
  var enemyGraphics = self.attachAsset('enemyShip', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 5;
  self.update = function () {
    self.y += self.speed;
    if (self.y > 2732) {
      self.destroy();
    }
  };
});
//<Assets used in the game will automatically appear here>
// Define a class for the Player's Ship
var PlayerShip = Container.expand(function () {
  var self = Container.call(this);
  var shipGraphics = self.attachAsset('playerShip', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 10;
  self.update = function () {
    // Update logic for the player's ship
  };
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x000000 //Init game with black background 
});
/****
* Game Code
****/
// Initialize player ship
var playerShip = game.addChild(new PlayerShip());
playerShip.x = 2048 / 2;
playerShip.y = 2500;
// Array to hold enemy ships
var enemies = [];
// Array to hold bullets
var bullets = [];
// Function to spawn enemy ships
function spawnEnemy() {
  var enemy = new EnemyShip();
  enemy.x = Math.random() * 2048;
  enemy.y = -50;
  enemies.push(enemy);
  game.addChild(enemy);
}
// Function to handle shooting
function shoot() {
  var bullet = new Bullet();
  bullet.x = playerShip.x;
  bullet.y = playerShip.y - 50;
  bullets.push(bullet);
  game.addChild(bullet);
}
// Handle game updates
game.update = function () {
  // Update player ship
  playerShip.update();
  // Update enemies
  for (var i = enemies.length - 1; i >= 0; i--) {
    enemies[i].update();
    if (enemies[i].intersects(playerShip)) {
      LK.effects.flashScreen(0xff0000, 1000);
      LK.showGameOver();
    }
  }
  // Update bullets
  for (var j = bullets.length - 1; j >= 0; j--) {
    bullets[j].update();
    for (var k = enemies.length - 1; k >= 0; k--) {
      if (bullets[j].intersects(enemies[k])) {
        bullets[j].destroy();
        enemies[k].destroy();
        bullets.splice(j, 1);
        enemies.splice(k, 1);
        LK.setScore(LK.getScore() + 1);
        break;
      }
    }
  }
  // Spawn enemies periodically
  if (LK.ticks % 60 == 0) {
    spawnEnemy();
  }
};
// Handle player ship movement
game.move = function (x, y, obj) {
  playerShip.x = x;
};
// Handle shooting
game.down = function (x, y, obj) {
  shoot();
}; /****
* Classes
****/
// Define a class for Bullets
var Bullet = Container.expand(function () {
  var self = Container.call(this);
  var bulletGraphics = self.attachAsset('bullet', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = -15;
  self.update = function () {
    self.y += self.speed;
    if (self.y < 0) {
      self.destroy();
    }
  };
});
// Define a class for Enemy Ships
var EnemyShip = Container.expand(function () {
  var self = Container.call(this);
  var enemyGraphics = self.attachAsset('enemyShip', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 5;
  self.update = function () {
    self.y += self.speed;
    if (self.y > 2732) {
      self.destroy();
    }
  };
});
//<Assets used in the game will automatically appear here>
// Define a class for the Player's Ship
var PlayerShip = Container.expand(function () {
  var self = Container.call(this);
  var shipGraphics = self.attachAsset('playerShip', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 10;
  self.update = function () {
    // Update logic for the player's ship
  };
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x000000 //Init game with black background 
});
/****
* Game Code
****/
// Initialize player ship
var playerShip = game.addChild(new PlayerShip());
playerShip.x = 2048 / 2;
playerShip.y = 2500;
// Array to hold enemy ships
var enemies = [];
// Array to hold bullets
var bullets = [];
// Function to spawn enemy ships
function spawnEnemy() {
  var enemy = new EnemyShip();
  enemy.x = Math.random() * 2048;
  enemy.y = -50;
  enemies.push(enemy);
  game.addChild(enemy);
}
// Function to handle shooting
function shoot() {
  var bullet = new Bullet();
  bullet.x = playerShip.x;
  bullet.y = playerShip.y - 50;
  bullets.push(bullet);
  game.addChild(bullet);
}
// Handle game updates
game.update = function () {
  // Update player ship
  playerShip.update();
  // Update enemies
  for (var i = enemies.length - 1; i >= 0; i--) {
    enemies[i].update();
    if (enemies[i].intersects(playerShip)) {
      LK.effects.flashScreen(0xff0000, 1000);
      LK.showGameOver();
    }
  }
  // Update bullets
  for (var j = bullets.length - 1; j >= 0; j--) {
    bullets[j].update();
    for (var k = enemies.length - 1; k >= 0; k--) {
      if (bullets[j].intersects(enemies[k])) {
        bullets[j].destroy();
        enemies[k].destroy();
        bullets.splice(j, 1);
        enemies.splice(k, 1);
        LK.setScore(LK.getScore() + 1);
        break;
      }
    }
  }
  // Spawn enemies periodically
  if (LK.ticks % 60 == 0) {
    spawnEnemy();
  }
};
// Handle player ship movement
game.move = function (x, y, obj) {
  playerShip.x = x;
};
// Handle shooting
game.down = function (x, y, obj) {
  shoot();
};
:quality(85)/https://cdn.frvr.ai/670fd318493ef6ddf89bbe45.png%3F3) 
 Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/670fd52a493ef6ddf89bbe5d.png%3F3) 
 Straight White fighter jet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/670fd656493ef6ddf89bbe69.png%3F3) 
 Straight black fighter jet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.