/****
* Classes
****/
// Chicken Nugget Enemy Class
var ChickenNugget = Container.expand(function () {
  var self = Container.call(this);
  var nuggetGraphics = self.attachAsset('chickenNugget', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.health = 5; // Health of the chicken nugget
  self.speed = 2; // Movement speed
  self.move = function () {
    // Movement logic for the chicken nugget
  };
  self.takeDamage = function (amount) {
    self.health -= amount;
    if (self.health <= 0) {
      self.destroy(); // Destroy the chicken nugget if health is 0 or less
    }
  };
});
// Assets will be automatically created based on usage in the code.
// Sauce Tower Class
var SauceTower = Container.expand(function () {
  var self = Container.call(this);
  var towerGraphics = self.attachAsset('sauceTower', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.range = 300; // Example range of the tower
  self.damage = 1; // Damage dealt by the tower
  self.cooldown = 60; // Cooldown in ticks (60 ticks = 1 second)
  self.tickSinceLastShot = 0;
  self.update = function () {
    // Tower attack logic
    if (self.tickSinceLastShot >= self.cooldown) {
      // Find and attack the nearest chicken nugget
      self.tickSinceLastShot = 0;
    } else {
      self.tickSinceLastShot++;
    }
  };
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
// Initialize important variables and arrays
var towers = [];
var enemies = [];
var spawnRate = 120; // Spawn an enemy every 2 seconds
var tickCount = 0;
// Main game loop
LK.on('tick', function () {
  // Spawn enemies
  if (tickCount % spawnRate === 0) {
    var newEnemy = new ChickenNugget();
    newEnemy.x = 100; // Starting X position
    newEnemy.y = -50; // Starting Y position (spawn above the screen)
    enemies.push(newEnemy);
    game.addChild(newEnemy);
  }
  // Update towers
  towers.forEach(function (tower) {
    tower.update();
  });
  // Update enemies
  enemies.forEach(function (enemy, index) {
    enemy.move();
    if (enemy.y > 2732) {
      // If the enemy goes off the bottom of the screen
      enemy.destroy();
      enemies.splice(index, 1);
    }
  });
  tickCount++;
});
// Example of placing a tower
game.on('down', function (obj) {
  var pos = obj.event.getLocalPosition(game);
  var newTower = new SauceTower();
  newTower.x = pos.x;
  newTower.y = pos.y;
  towers.push(newTower);
  game.addChild(newTower);
}); /****
* Classes
****/
// Chicken Nugget Enemy Class
var ChickenNugget = Container.expand(function () {
  var self = Container.call(this);
  var nuggetGraphics = self.attachAsset('chickenNugget', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.health = 5; // Health of the chicken nugget
  self.speed = 2; // Movement speed
  self.move = function () {
    // Movement logic for the chicken nugget
  };
  self.takeDamage = function (amount) {
    self.health -= amount;
    if (self.health <= 0) {
      self.destroy(); // Destroy the chicken nugget if health is 0 or less
    }
  };
});
// Assets will be automatically created based on usage in the code.
// Sauce Tower Class
var SauceTower = Container.expand(function () {
  var self = Container.call(this);
  var towerGraphics = self.attachAsset('sauceTower', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.range = 300; // Example range of the tower
  self.damage = 1; // Damage dealt by the tower
  self.cooldown = 60; // Cooldown in ticks (60 ticks = 1 second)
  self.tickSinceLastShot = 0;
  self.update = function () {
    // Tower attack logic
    if (self.tickSinceLastShot >= self.cooldown) {
      // Find and attack the nearest chicken nugget
      self.tickSinceLastShot = 0;
    } else {
      self.tickSinceLastShot++;
    }
  };
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
// Initialize important variables and arrays
var towers = [];
var enemies = [];
var spawnRate = 120; // Spawn an enemy every 2 seconds
var tickCount = 0;
// Main game loop
LK.on('tick', function () {
  // Spawn enemies
  if (tickCount % spawnRate === 0) {
    var newEnemy = new ChickenNugget();
    newEnemy.x = 100; // Starting X position
    newEnemy.y = -50; // Starting Y position (spawn above the screen)
    enemies.push(newEnemy);
    game.addChild(newEnemy);
  }
  // Update towers
  towers.forEach(function (tower) {
    tower.update();
  });
  // Update enemies
  enemies.forEach(function (enemy, index) {
    enemy.move();
    if (enemy.y > 2732) {
      // If the enemy goes off the bottom of the screen
      enemy.destroy();
      enemies.splice(index, 1);
    }
  });
  tickCount++;
});
// Example of placing a tower
game.on('down', function (obj) {
  var pos = obj.event.getLocalPosition(game);
  var newTower = new SauceTower();
  newTower.x = pos.x;
  newTower.y = pos.y;
  towers.push(newTower);
  game.addChild(newTower);
});