/**** * Classes ****/ // Fireball class var Fireball = Container.expand(function () { var self = Container.call(this); var fireballGraphics = self.attachAsset('fireball', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y -= self.speed; // Destroy fireball if it goes off screen if (self.y < -self.height) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Ninja class var Ninja = Container.expand(function () { var self = Container.call(this); var ninjaGraphics = self.attachAsset('ninja', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for ninja }; self.summonJutsu = function () { // Summoning jutsu logic }; self.fireBallJutsu = function () { // Fireball jutsu logic }; }); // Summon class var Summon = Container.expand(function () { var self = Container.call(this); var summonGraphics = self.attachAsset('summon', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for summon }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize ninja var ninja = game.addChild(new Ninja()); ninja.x = 2048 / 2; ninja.y = 2732 - 200; // Initialize arrays for summons and fireballs var summons = []; var fireballs = []; // Handle move events function handleMove(x, y, obj) { // Move ninja to touch position ninja.x = x; ninja.y = y; } // Handle down events game.down = function (x, y, obj) { handleMove(x, y, obj); // Perform summoning jutsu var newSummon = new Summon(); newSummon.x = ninja.x; newSummon.y = ninja.y; summons.push(newSummon); game.addChild(newSummon); }; // Handle up events game.up = function (x, y, obj) { // Perform fireball jutsu var newFireball = new Fireball(); newFireball.x = ninja.x; newFireball.y = ninja.y; fireballs.push(newFireball); game.addChild(newFireball); }; // Update game logic game.update = function () { // Update summons for (var i = summons.length - 1; i >= 0; i--) { summons[i].update(); // Destroy summon if it goes off screen if (summons[i].y < -summons[i].height) { summons[i].destroy(); summons.splice(i, 1); } } // Update fireballs for (var j = fireballs.length - 1; j >= 0; j--) { fireballs[j].update(); // Destroy fireball if it goes off screen if (fireballs[j].y < -fireballs[j].height) { fireballs[j].destroy(); fireballs.splice(j, 1); } } }; // Set initial score var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Update score function updateScore() { scoreTxt.setText(LK.getScore()); } // Initialize score LK.setScore(0); updateScore();
/****
* Classes
****/
// Fireball class
var Fireball = Container.expand(function () {
var self = Container.call(this);
var fireballGraphics = self.attachAsset('fireball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
self.y -= self.speed;
// Destroy fireball if it goes off screen
if (self.y < -self.height) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Ninja class
var Ninja = Container.expand(function () {
var self = Container.call(this);
var ninjaGraphics = self.attachAsset('ninja', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for ninja
};
self.summonJutsu = function () {
// Summoning jutsu logic
};
self.fireBallJutsu = function () {
// Fireball jutsu logic
};
});
// Summon class
var Summon = Container.expand(function () {
var self = Container.call(this);
var summonGraphics = self.attachAsset('summon', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for summon
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize ninja
var ninja = game.addChild(new Ninja());
ninja.x = 2048 / 2;
ninja.y = 2732 - 200;
// Initialize arrays for summons and fireballs
var summons = [];
var fireballs = [];
// Handle move events
function handleMove(x, y, obj) {
// Move ninja to touch position
ninja.x = x;
ninja.y = y;
}
// Handle down events
game.down = function (x, y, obj) {
handleMove(x, y, obj);
// Perform summoning jutsu
var newSummon = new Summon();
newSummon.x = ninja.x;
newSummon.y = ninja.y;
summons.push(newSummon);
game.addChild(newSummon);
};
// Handle up events
game.up = function (x, y, obj) {
// Perform fireball jutsu
var newFireball = new Fireball();
newFireball.x = ninja.x;
newFireball.y = ninja.y;
fireballs.push(newFireball);
game.addChild(newFireball);
};
// Update game logic
game.update = function () {
// Update summons
for (var i = summons.length - 1; i >= 0; i--) {
summons[i].update();
// Destroy summon if it goes off screen
if (summons[i].y < -summons[i].height) {
summons[i].destroy();
summons.splice(i, 1);
}
}
// Update fireballs
for (var j = fireballs.length - 1; j >= 0; j--) {
fireballs[j].update();
// Destroy fireball if it goes off screen
if (fireballs[j].y < -fireballs[j].height) {
fireballs[j].destroy();
fireballs.splice(j, 1);
}
}
};
// Set initial score
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update score
function updateScore() {
scoreTxt.setText(LK.getScore());
}
// Initialize score
LK.setScore(0);
updateScore();