/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; }; }); // Character class var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.shoot = function () { var newBullet = new Bullet(); newBullet.x = self.x; newBullet.y = self.y; bullets.push(newBullet); game.addChild(newBullet); }; self.shootRose = function () { var newRose = new Rose(); newRose.x = self.x; newRose.y = self.y; bullets.push(newRose); game.addChild(newRose); }; }); var Rose = Container.expand(function () { var self = Container.call(this); var roseGraphics = self.attachAsset('rose', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize variables var bullets = []; var character = game.addChild(new Character()); character.x = 2048 / 2; character.y = 2732 - 200; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle game move events game.move = function (x, y, obj) { character.x = x; character.y = y; }; // Handle game down events game.down = function (x, y, obj) { character.shootRose(); }; // Update game state game.update = function () { for (var i = bullets.length - 1; i >= 0; i--) { if (bullets[i].y < -50) { bullets[i].destroy(); bullets.splice(i, 1); } } if (LK.ticks % 30 == 0) { character.shoot(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,74 +1,92 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
// Bullet class
var Bullet = Container.expand(function () {
- var self = Container.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = -10;
- self.update = function () {
- self.y += self.speed;
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -10;
+ self.update = function () {
+ self.y += self.speed;
+ };
});
// Character class
var Character = Container.expand(function () {
- var self = Container.call(this);
- var characterGraphics = self.attachAsset('character', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.shoot = function () {
- var newBullet = new Bullet();
- newBullet.x = self.x;
- newBullet.y = self.y;
- bullets.push(newBullet);
- game.addChild(newBullet);
- };
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.shoot = function () {
+ var newBullet = new Bullet();
+ newBullet.x = self.x;
+ newBullet.y = self.y;
+ bullets.push(newBullet);
+ game.addChild(newBullet);
+ };
+ self.shootRose = function () {
+ var newRose = new Rose();
+ newRose.x = self.x;
+ newRose.y = self.y;
+ bullets.push(newRose);
+ game.addChild(newRose);
+ };
});
+var Rose = Container.expand(function () {
+ var self = Container.call(this);
+ var roseGraphics = self.attachAsset('rose', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -10;
+ self.update = function () {
+ self.y += self.speed;
+ };
+});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize variables
var bullets = [];
var character = game.addChild(new Character());
character.x = 2048 / 2;
character.y = 2732 - 200;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle game move events
game.move = function (x, y, obj) {
- character.x = x;
- character.y = y;
+ character.x = x;
+ character.y = y;
};
// Handle game down events
game.down = function (x, y, obj) {
- character.shoot();
+ character.shootRose();
};
// Update game state
game.update = function () {
- for (var i = bullets.length - 1; i >= 0; i--) {
- if (bullets[i].y < -50) {
- bullets[i].destroy();
- bullets.splice(i, 1);
- }
- }
- if (LK.ticks % 30 == 0) {
- character.shoot();
- }
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ if (bullets[i].y < -50) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ }
+ }
+ if (LK.ticks % 30 == 0) {
+ character.shoot();
+ }
};
\ No newline at end of file