/**** * Classes ****/ // Define the 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; if (self.y < -self.height) { self.destroy(); } }; }); // Define the 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 = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -self.height; } }; }); //<Assets used in the game will automatically appear here> // Define the 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 }; self.move = function (x, y) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Add city road background var cityRoadBg = LK.getAsset('cityroad', { anchorX: 0.5, anchorY: 0, x: 2048 / 2, y: 0, width: 2048, height: 2732 }); game.addChild(cityRoadBg); // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 200; // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = game.addChild(new Enemy()); enemy.x = Math.random() * 2048; enemy.y = Math.random() * -2732; enemies.push(enemy); } // Initialize bullets var bullets = []; // Handle player movement game.move = function (x, y, obj) { player.move(x, y); }; // Handle shooting game.down = function (x, y, obj) { var bullet = game.addChild(new Bullet()); bullet.x = player.x; bullet.y = player.y; bullets.push(bullet); }; // Update game state game.update = function () { // Update player player.update(); // Update enemies for (var i = 0; i < enemies.length; i++) { enemies[i].update(); } // Update bullets for (var j = 0; j < bullets.length; j++) { bullets[j].update(); } // Check for collisions for (var k = 0; k < bullets.length; k++) { for (var l = 0; l < enemies.length; l++) { if (bullets[k].intersects(enemies[l])) { bullets[k].destroy(); enemies[l].destroy(); bullets.splice(k, 1); enemies.splice(l, 1); // Spawn a new enemy at a random position at the top var newEnemy = game.addChild(new Enemy()); newEnemy.x = Math.random() * 2048; newEnemy.y = Math.random() * -500; // spawn slightly above the screen enemies.push(newEnemy); break; } } } };
===================================================================
--- original.js
+++ change.js
@@ -58,8 +58,18 @@
/****
* Game Code
****/
+// Add city road background
+var cityRoadBg = LK.getAsset('cityroad', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 2048 / 2,
+ y: 0,
+ width: 2048,
+ height: 2732
+});
+game.addChild(cityRoadBg);
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
bulet. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
police. In-Game asset. 2d. High contrast. No shadows
criminal. In-Game asset. 2d. High contrast. No shadows
Road. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat