/**** * Classes ****/ // Define an Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); //<Assets used in the game will automatically appear here> // Define a Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 150; // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 1000; enemies.push(enemy); game.addChild(enemy); } // Bullet array initialization removed // Handle player movement game.move = function (x, y, obj) { player.x = x; player.y = y; }; // Handle shooting game.down = function (x, y, obj) { // Shooting logic removed }; // Game update loop game.update = function () { // Update enemies for (var i = 0; i < enemies.length; i++) { enemies[i].update(); if (player.intersects(enemies[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Bullet update logic removed };
===================================================================
--- original.js
+++ change.js
@@ -1,19 +1,7 @@
/****
* Classes
****/
-// Define a 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;
- };
-});
// Define an Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
@@ -46,9 +34,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x1e1e1e //Init game with dark grey background
+ backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
@@ -65,22 +53,17 @@
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
-// Initialize bullets
-var bullets = [];
+// Bullet array initialization removed
// Handle player movement
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Handle shooting
game.down = function (x, y, obj) {
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y;
- bullets.push(bullet);
- game.addChild(bullet);
+ // Shooting logic removed
};
// Game update loop
game.update = function () {
// Update enemies
@@ -90,22 +73,6 @@
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
- // Update bullets
- for (var j = bullets.length - 1; j >= 0; j--) {
- bullets[j].update();
- for (var k = enemies.length - 1; k >= 0; k--) {
- if (bullets[j].intersects(enemies[k])) {
- bullets[j].destroy();
- bullets.splice(j, 1);
- enemies[k].destroy();
- enemies.splice(k, 1);
- break;
- }
- }
- if (bullets[j] && bullets[j].y < -50) {
- bullets[j].destroy();
- bullets.splice(j, 1);
- }
- }
+ // Bullet update logic removed
};
\ No newline at end of file