/**** * Classes ****/ // 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.destroy(); } }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); // Hero rocket launcher var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Tank class var Tank = Container.expand(function () { var self = Container.call(this); var tankGraphics = self.attachAsset('tank', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Update logic for tank }; self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y; game.addChild(bullet); heroBullets.push(bullet); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var heroBullets = []; var enemyBullets = []; var enemies = []; var score = 0; // Create tank instance var tank = new Tank(); tank.x = 2048 / 2; tank.y = 2732 - 200; game.addChild(tank); // Create score text var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle game updates game.update = function () { // Update tank tank.update(); // Update hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].update(); if (heroBullets[i].intersects(enemies)) { heroBullets[i].destroy(); heroBullets.splice(i, 1); score += 10; scoreTxt.setText(score); } } // Update enemy bullets for (var j = enemyBullets.length - 1; j >= 0; j--) { enemyBullets[j].update(); if (enemyBullets[j].intersects(tank)) { enemyBullets[j].destroy(); enemyBullets.splice(j, 1); LK.showGameOver(); } } // Update enemies for (var k = enemies.length - 1; k >= 0; k--) { enemies[k].update(); if (enemies[k].intersects(tank)) { enemies[k].destroy(); enemies.splice(k, 1); LK.showGameOver(); } } // Spawn new enemies if (LK.ticks % 60 == 0) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = 0; game.addChild(enemy); enemies.push(enemy); } }; // Handle touch events game.down = function (x, y, obj) { tank.shoot(); }; game.move = function (x, y, obj) { tank.x = x; tank.y = y; }; game.up = function (x, y, obj) {};
===================================================================
--- original.js
+++ change.js
@@ -142,7 +142,5 @@
game.move = function (x, y, obj) {
tank.x = x;
tank.y = y;
};
-game.up = function (x, y, obj) {
- // No action needed on touch up
-};
\ No newline at end of file
+game.up = function (x, y, obj) {};
\ No newline at end of file