===================================================================
--- original.js
+++ change.js
@@ -1,85 +1,86 @@
-/****
+/****
* 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 = 5;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
// Player class
var Player = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Player update logic if needed
- };
- self.down = function (x, y, obj) {
- self.x = x;
- self.y = y;
- };
- self.move = function (x, y, obj) {
- self.x = x;
- self.y = y;
- };
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ shape: 'ellipse'
+ });
+ self.update = function () {
+ // Player update logic if needed
+ };
+ self.down = function (x, y, obj) {
+ self.x = x;
+ self.y = y;
+ };
+ self.move = function (x, y, obj) {
+ self.x = x;
+ self.y = y;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
var bullets = [];
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.update = function () {
- for (var i = bullets.length - 1; i >= 0; i--) {
- bullets[i].update();
- if (bullets[i].intersects(player)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
- if (LK.ticks % 30 == 0) {
- var newBullet = new Bullet();
- newBullet.x = Math.random() * 2048;
- newBullet.y = -50;
- bullets.push(newBullet);
- game.addChild(newBullet);
- }
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].update();
+ if (bullets[i].intersects(player)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ if (LK.ticks % 30 == 0) {
+ var newBullet = new Bullet();
+ newBullet.x = Math.random() * 2048;
+ newBullet.y = -50;
+ bullets.push(newBullet);
+ game.addChild(newBullet);
+ }
};
game.down = function (x, y, obj) {
- player.down(x, y, obj);
+ player.down(x, y, obj);
};
game.move = function (x, y, obj) {
- player.move(x, y, obj);
+ player.move(x, y, obj);
};
game.up = function (x, y, obj) {
- // No action needed on up event
+ // No action needed on up event
};
\ No newline at end of file