/****
* Classes
****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Define a class for the Pokeball
var Pokeball = Container.expand(function () {
  var self = Container.call(this);
  var pokeballGraphics = self.attachAsset('pokeball', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 5;
  self.update = function () {
    self.y -= self.speed;
  };
});
// Define a class for the Pokemon
var Pokemon = Container.expand(function () {
  var self = Container.call(this);
  var pokemonGraphics = self.attachAsset('pokemon', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.update = function () {
    // Pokemon movement logic can be added here
  };
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var pokeballs = [];
var pokemons = [];
var score = 0;
// Create score display
var scoreTxt = new Text2('Score: 0', {
  size: 100,
  fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new Pokemon
function spawnPokemon() {
  var newPokemon = new Pokemon();
  newPokemon.x = Math.random() * 2048;
  newPokemon.y = Math.random() * 1000 + 1000; // Start below the screen
  pokemons.push(newPokemon);
  game.addChild(newPokemon);
}
// Handle game touch events
game.down = function (x, y, obj) {
  var newPokeball = new Pokeball();
  newPokeball.x = x;
  newPokeball.y = y;
  pokeballs.push(newPokeball);
  game.addChild(newPokeball);
};
// Update game logic
game.update = function () {
  // Update pokeballs
  for (var i = pokeballs.length - 1; i >= 0; i--) {
    pokeballs[i].update();
    if (pokeballs[i].y < -50) {
      pokeballs[i].destroy();
      pokeballs.splice(i, 1);
    }
  }
  // Update pokemons
  for (var j = pokemons.length - 1; j >= 0; j--) {
    pokemons[j].update();
    if (pokemons[j].y < -50) {
      pokemons[j].destroy();
      pokemons.splice(j, 1);
    }
  }
  // Check for collisions
  for (var k = pokeballs.length - 1; k >= 0; k--) {
    for (var l = pokemons.length - 1; l >= 0; l--) {
      if (pokeballs[k].intersects(pokemons[l])) {
        score += 10;
        scoreTxt.setText('Score: ' + score);
        pokeballs[k].destroy();
        pokemons[l].destroy();
        pokeballs.splice(k, 1);
        pokemons.splice(l, 1);
        break;
      }
    }
  }
  // Spawn new Pokemon every 60 ticks
  if (LK.ticks % 60 == 0) {
    spawnPokemon();
  }
}; /****
* Classes
****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Define a class for the Pokeball
var Pokeball = Container.expand(function () {
  var self = Container.call(this);
  var pokeballGraphics = self.attachAsset('pokeball', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.speed = 5;
  self.update = function () {
    self.y -= self.speed;
  };
});
// Define a class for the Pokemon
var Pokemon = Container.expand(function () {
  var self = Container.call(this);
  var pokemonGraphics = self.attachAsset('pokemon', {
    anchorX: 0.5,
    anchorY: 0.5
  });
  self.update = function () {
    // Pokemon movement logic can be added here
  };
});
/****
* Initialize Game
****/
var game = new LK.Game({
  backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var pokeballs = [];
var pokemons = [];
var score = 0;
// Create score display
var scoreTxt = new Text2('Score: 0', {
  size: 100,
  fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new Pokemon
function spawnPokemon() {
  var newPokemon = new Pokemon();
  newPokemon.x = Math.random() * 2048;
  newPokemon.y = Math.random() * 1000 + 1000; // Start below the screen
  pokemons.push(newPokemon);
  game.addChild(newPokemon);
}
// Handle game touch events
game.down = function (x, y, obj) {
  var newPokeball = new Pokeball();
  newPokeball.x = x;
  newPokeball.y = y;
  pokeballs.push(newPokeball);
  game.addChild(newPokeball);
};
// Update game logic
game.update = function () {
  // Update pokeballs
  for (var i = pokeballs.length - 1; i >= 0; i--) {
    pokeballs[i].update();
    if (pokeballs[i].y < -50) {
      pokeballs[i].destroy();
      pokeballs.splice(i, 1);
    }
  }
  // Update pokemons
  for (var j = pokemons.length - 1; j >= 0; j--) {
    pokemons[j].update();
    if (pokemons[j].y < -50) {
      pokemons[j].destroy();
      pokemons.splice(j, 1);
    }
  }
  // Check for collisions
  for (var k = pokeballs.length - 1; k >= 0; k--) {
    for (var l = pokemons.length - 1; l >= 0; l--) {
      if (pokeballs[k].intersects(pokemons[l])) {
        score += 10;
        scoreTxt.setText('Score: ' + score);
        pokeballs[k].destroy();
        pokemons[l].destroy();
        pokeballs.splice(k, 1);
        pokemons.splice(l, 1);
        break;
      }
    }
  }
  // Spawn new Pokemon every 60 ticks
  if (LK.ticks % 60 == 0) {
    spawnPokemon();
  }
};