/****
* 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);
};
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;
game.down = function (x, y, obj) {
character.shootRose();
};
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();
character.shootRose();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -34,8 +34,15 @@
newRose.y = self.y;
bullets.push(newRose);
game.addChild(newRose);
};
+ 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', {
@@ -62,8 +69,11 @@
var bullets = [];
var character = game.addChild(new Character());
character.x = 2048 / 2;
character.y = 2732 - 200;
+game.down = function (x, y, obj) {
+ character.shootRose();
+};
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
@@ -87,6 +97,7 @@
}
}
if (LK.ticks % 30 == 0) {
character.shoot();
+ character.shootRose();
}
};
\ No newline at end of file