User prompt
Make enemy shoot
User prompt
Make enemy shoot once
User prompt
Add space background
User prompt
Make enemy bullets slower than players bullets
User prompt
Make bullets cancel each other
User prompt
Make ufo to shoot in random order
User prompt
Enemy can't shoot
User prompt
Create a new level when player scored 100 points
User prompt
End the game if when maximum of three enemies cross player
User prompt
Fix the bug
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'health')' in or related to this line: 'jet.health = 3;' Line Number: 53
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'health')' in or related to this line: 'self.health = 3;' Line Number: 169
User prompt
Make player get damge from enemy bullets
User prompt
Make player get damge
User prompt
Make the enemy shoot the player
User prompt
Make the jet move left and right
Initial prompt
Space shooter
/**** * Classes ****/ // 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 = 3; self.update = function () { self.y += self.speed; if (self.y > 2732 + bulletGraphics.height) { self.destroy(); enemyBullets.splice(enemyBullets.indexOf(self), 1); } }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); //<Assets used in the game will automatically appear here> // Jet class var Jet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.health = 3; self.update = function () { // Jet update logic }; self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - jetGraphics.height / 2; game.addChild(bullet); heroBullets.push(bullet); }; }); // UFO class var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732 + ufoGraphics.height) { self.destroy(); ufos.splice(ufos.indexOf(self), 1); enemiesCrossed++; } }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + ufoGraphics.height / 2; game.addChild(bullet); enemyBullets.push(bullet); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var background = game.attachAsset('background', { anchorX: 0.0, anchorY: 0.0, x: 0, y: 0 }); var jet; var heroBullets = []; var ufos = []; var enemyBullets = []; var score = 0; var enemiesCrossed = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function spawnUFO() { var ufo = new UFO(); ufo.x = Math.random() * 2048; ufo.y = -ufo.height; game.addChild(ufo); ufos.push(ufo); } game.update = function () { jet.update(); heroBullets.forEach(function (bullet) { bullet.update(); }); ufos.forEach(function (ufo) { ufo.update(); if (Math.random() < 0.01) { ufo.shoot(); } }); enemyBullets.forEach(function (bullet) { bullet.update(); }); enemyBullets.forEach(function (bullet) { bullet.update(); }); game.move = function (x, y, obj) { jet.x = x; }; for (var i = heroBullets.length - 1; i >= 0; i--) { for (var j = ufos.length - 1; j >= 0; j--) { if (heroBullets[i].intersects(ufos[j])) { heroBullets[i].destroy(); heroBullets.splice(i, 1); ufos[j].destroy(); ufos.splice(j, 1); score += 10; scoreTxt.setText(score); break; } } } for (var i = enemyBullets.length - 1; i >= 0; i--) { if (enemyBullets[i].intersects(jet)) { enemyBullets[i].destroy(); enemyBullets.splice(i, 1); jet.health -= 1; if (jet.health <= 0 || enemiesCrossed >= 3) { LK.showGameOver(); } else if (score >= 100) { score = 0; scoreTxt.setText(score); enemiesCrossed = 0; jet.health = 3; heroBullets.forEach(function (bullet) { bullet.destroy(); }); heroBullets = []; ufos.forEach(function (ufo) { ufo.destroy(); }); ufos = []; } break; } // Check if enemy bullet intersects with hero bullet for (var j = heroBullets.length - 1; j >= 0; j--) { if (enemyBullets[i] && enemyBullets[i].intersects(heroBullets[j])) { // Destroy both bullets enemyBullets[i].destroy(); enemyBullets.splice(i, 1); heroBullets[j].destroy(); heroBullets.splice(j, 1); break; } } } // Spawn UFOs periodically if (LK.ticks % 60 == 0) { spawnUFO(); } }; game.down = function (x, y, obj) { jet.shoot(); }; jet = game.addChild(new Jet()); jet.x = 2048 / 2; jet.y = 2732 - 200; jet.health = 3;
===================================================================
--- original.js
+++ change.js
@@ -75,9 +75,8 @@
bullet.x = self.x;
bullet.y = self.y + ufoGraphics.height / 2;
game.addChild(bullet);
enemyBullets.push(bullet);
- enemyBullets.push(bullet);
};
});
/****
Fighter jet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Ufo with green alien driving it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Space with stars with earth background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red round ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Green round ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel smoke. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red Heart with plus symbol at centre. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.