/**** * Classes ****/ // Define a class for Pokéball var Pokeball = Container.expand(function () { var self = Container.call(this); var pokeballGraphics = self.attachAsset('pokeball', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for Pokéball self.y -= 5; // Move Pokéball upwards // Make the pokeball move in a zig zag pattern if (LK.ticks % 20 < 10) { self.x += 5; } else { self.x -= 5; } }; }); //<Assets used in the game will automatically appear here> // Define a class for Pokémon var Pokemon = Container.expand(function () { var self = Container.call(this); var pokemonGraphics = self.attachAsset('pokemon', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for Pokémon }; }); // Define a class for Trainer var Trainer = Container.expand(function () { var self = Container.call(this); var trainerGraphics = self.attachAsset('trainer', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for Trainer }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var pokemons = []; var trainer; var pokeballs = []; var score = 0; // Create and add a Trainer to the game trainer = game.addChild(new Trainer()); trainer.x = 2048 / 2; trainer.y = 2732 - 200; // Function to spawn a Pokémon function spawnPokemon() { var newPokemon = new Pokemon(); newPokemon.x = Math.random() * 2048; newPokemon.y = 0; pokemons.push(newPokemon); game.addChild(newPokemon); } // Function to throw a Pokéball function throwPokeball() { var newPokeball = new Pokeball(); newPokeball.x = trainer.x; newPokeball.y = trainer.y; pokeballs.push(newPokeball); game.addChild(newPokeball); } // Handle game updates game.update = function () { // Update Pokémon positions pokemons.forEach(function (pokemon) { pokemon.y += 2; // Move Pokémon downwards if (pokemon.y > 2732) { pokemon.destroy(); pokemons.splice(pokemons.indexOf(pokemon), 1); } }); // Update Pokéball positions pokeballs.forEach(function (pokeball) { pokeball.y -= 5; // Move Pokéball upwards if (pokeball.y < 0) { pokeball.destroy(); pokeballs.splice(pokeballs.indexOf(pokeball), 1); } }); // Check for collisions between Pokéballs and Pokémon pokeballs.forEach(function (pokeball) { pokemons.forEach(function (pokemon) { if (pokeball.intersects(pokemon)) { score += 1; pokeball.destroy(); pokemon.destroy(); pokeballs.splice(pokeballs.indexOf(pokeball), 1); pokemons.splice(pokemons.indexOf(pokemon), 1); } }); }); }; // Handle touch events for throwing Pokéballs game.down = function (x, y, obj) { throwPokeball(); }; // Spawn Pokémon at intervals var spawnInterval = LK.setInterval(spawnPokemon, 2000);
===================================================================
--- original.js
+++ change.js
@@ -1,52 +1,59 @@
-/****
+/****
* Classes
-****/
+****/
// Define a class for Pokéball
var Pokeball = Container.expand(function () {
- var self = Container.call(this);
- var pokeballGraphics = self.attachAsset('pokeball', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Update logic for Pokéball
- };
+ var self = Container.call(this);
+ var pokeballGraphics = self.attachAsset('pokeball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for Pokéball
+ self.y -= 5; // Move Pokéball upwards
+ // Make the pokeball move in a zig zag pattern
+ if (LK.ticks % 20 < 10) {
+ self.x += 5;
+ } else {
+ self.x -= 5;
+ }
+ };
});
//<Assets used in the game will automatically appear here>
// Define a class for Pokémon
var Pokemon = Container.expand(function () {
- var self = Container.call(this);
- var pokemonGraphics = self.attachAsset('pokemon', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Update logic for Pokémon
- };
+ var self = Container.call(this);
+ var pokemonGraphics = self.attachAsset('pokemon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for Pokémon
+ };
});
// Define a class for Trainer
var Trainer = Container.expand(function () {
- var self = Container.call(this);
- var trainerGraphics = self.attachAsset('trainer', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Update logic for Trainer
- };
+ var self = Container.call(this);
+ var trainerGraphics = self.attachAsset('trainer', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for Trainer
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize arrays and variables
var pokemons = [];
var trainer;
var pokeballs = [];
@@ -56,55 +63,55 @@
trainer.x = 2048 / 2;
trainer.y = 2732 - 200;
// Function to spawn a Pokémon
function spawnPokemon() {
- var newPokemon = new Pokemon();
- newPokemon.x = Math.random() * 2048;
- newPokemon.y = 0;
- pokemons.push(newPokemon);
- game.addChild(newPokemon);
+ var newPokemon = new Pokemon();
+ newPokemon.x = Math.random() * 2048;
+ newPokemon.y = 0;
+ pokemons.push(newPokemon);
+ game.addChild(newPokemon);
}
// Function to throw a Pokéball
function throwPokeball() {
- var newPokeball = new Pokeball();
- newPokeball.x = trainer.x;
- newPokeball.y = trainer.y;
- pokeballs.push(newPokeball);
- game.addChild(newPokeball);
+ var newPokeball = new Pokeball();
+ newPokeball.x = trainer.x;
+ newPokeball.y = trainer.y;
+ pokeballs.push(newPokeball);
+ game.addChild(newPokeball);
}
// Handle game updates
game.update = function () {
- // Update Pokémon positions
- pokemons.forEach(function (pokemon) {
- pokemon.y += 2; // Move Pokémon downwards
- if (pokemon.y > 2732) {
- pokemon.destroy();
- pokemons.splice(pokemons.indexOf(pokemon), 1);
- }
- });
- // Update Pokéball positions
- pokeballs.forEach(function (pokeball) {
- pokeball.y -= 5; // Move Pokéball upwards
- if (pokeball.y < 0) {
- pokeball.destroy();
- pokeballs.splice(pokeballs.indexOf(pokeball), 1);
- }
- });
- // Check for collisions between Pokéballs and Pokémon
- pokeballs.forEach(function (pokeball) {
- pokemons.forEach(function (pokemon) {
- if (pokeball.intersects(pokemon)) {
- score += 1;
- pokeball.destroy();
- pokemon.destroy();
- pokeballs.splice(pokeballs.indexOf(pokeball), 1);
- pokemons.splice(pokemons.indexOf(pokemon), 1);
- }
- });
- });
+ // Update Pokémon positions
+ pokemons.forEach(function (pokemon) {
+ pokemon.y += 2; // Move Pokémon downwards
+ if (pokemon.y > 2732) {
+ pokemon.destroy();
+ pokemons.splice(pokemons.indexOf(pokemon), 1);
+ }
+ });
+ // Update Pokéball positions
+ pokeballs.forEach(function (pokeball) {
+ pokeball.y -= 5; // Move Pokéball upwards
+ if (pokeball.y < 0) {
+ pokeball.destroy();
+ pokeballs.splice(pokeballs.indexOf(pokeball), 1);
+ }
+ });
+ // Check for collisions between Pokéballs and Pokémon
+ pokeballs.forEach(function (pokeball) {
+ pokemons.forEach(function (pokemon) {
+ if (pokeball.intersects(pokemon)) {
+ score += 1;
+ pokeball.destroy();
+ pokemon.destroy();
+ pokeballs.splice(pokeballs.indexOf(pokeball), 1);
+ pokemons.splice(pokemons.indexOf(pokemon), 1);
+ }
+ });
+ });
};
// Handle touch events for throwing Pokéballs
game.down = function (x, y, obj) {
- throwPokeball();
+ throwPokeball();
};
// Spawn Pokémon at intervals
var spawnInterval = LK.setInterval(spawnPokemon, 2000);
\ No newline at end of file