User prompt
The scoring system: each missile shot down equals 50 points. Each Alien shot down, equals 150 points. Can you display the score at the top left.
User prompt
if the heromissile collides then it should also explode
User prompt
And if the jet fighter's missile hits an alien or an alien missile, then that alien or its missile should explode and disappear from the screen
User prompt
if the jet fight hits an alien or a missile from an alien, then there should be a crash and the game is over.
Code edit (1 edits merged)
Please save this source code
Initial prompt
Attack on Earth
/**** * Classes ****/ // Alien class var Alien = Container.expand(function () { var self = Container.call(this); var alienGraphics = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732 + 50) { self.destroy(); aliens.splice(aliens.indexOf(self), 1); } }; self.shoot = function () { if (enemyMissiles.length < 4) { var missile = new EnemyMissile(); missile.x = self.x; missile.y = self.y + alienGraphics.height / 2; enemyMissiles.push(missile); game.addChild(missile); } }; }); // EnemyMissile class var EnemyMissile = Container.expand(function () { var self = Container.call(this); var missileGraphics = self.attachAsset('enemyMissile', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 2732 + 50) { self.destroy(); enemyMissiles.splice(enemyMissiles.indexOf(self), 1); } }; }); // Assets will be automatically created and loaded based on their usage in the code. // FighterJet class var FighterJet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('fighterJet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Update logic for the fighter jet }; self.shoot = function () { if (heroMissiles.length < 4) { var missile = new HeroMissile(); missile.x = self.x; missile.y = self.y - jetGraphics.height / 2; heroMissiles.push(missile); game.addChild(missile); } }; }); // HeroMissile class var HeroMissile = Container.expand(function () { var self = Container.call(this); var missileGraphics = self.attachAsset('heroMissile', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -50) { self.destroy(); heroMissiles.splice(heroMissiles.indexOf(self), 1); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var fighterJet = game.addChild(new FighterJet()); fighterJet.x = 2048 / 2; fighterJet.y = 2732 - 200; var heroMissiles = []; var aliens = []; var enemyMissiles = []; // Handle game move events game.move = function (x, y, obj) { fighterJet.x = x; fighterJet.y = y; }; // Handle game down events game.down = function (x, y, obj) { fighterJet.shoot(); }; // Game update loop game.update = function () { // Update all missiles heroMissiles.forEach(function (missile) { missile.update(); }); enemyMissiles.forEach(function (missile) { missile.update(); }); // Update all aliens aliens.forEach(function (alien) { alien.update(); if (Math.random() < 0.01) { alien.shoot(); } }); // Spawn new aliens if (LK.ticks % 60 == 0) { var alien = new Alien(); alien.x = Math.random() * 2048; alien.y = -50; aliens.push(alien); game.addChild(alien); } };
===================================================================
--- original.js
+++ change.js
@@ -1,133 +1,133 @@
-/****
+/****
* Classes
-****/
+****/
// Alien class
var Alien = Container.expand(function () {
- var self = Container.call(this);
- var alienGraphics = self.attachAsset('alien', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732 + 50) {
- self.destroy();
- aliens.splice(aliens.indexOf(self), 1);
- }
- };
- self.shoot = function () {
- if (enemyMissiles.length < 1) {
- var missile = new EnemyMissile();
- missile.x = self.x;
- missile.y = self.y + alienGraphics.height / 2;
- enemyMissiles.push(missile);
- game.addChild(missile);
- }
- };
+ var self = Container.call(this);
+ var alienGraphics = self.attachAsset('alien', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ aliens.splice(aliens.indexOf(self), 1);
+ }
+ };
+ self.shoot = function () {
+ if (enemyMissiles.length < 4) {
+ var missile = new EnemyMissile();
+ missile.x = self.x;
+ missile.y = self.y + alienGraphics.height / 2;
+ enemyMissiles.push(missile);
+ game.addChild(missile);
+ }
+ };
});
// EnemyMissile class
var EnemyMissile = Container.expand(function () {
- var self = Container.call(this);
- var missileGraphics = self.attachAsset('enemyMissile', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732 + 50) {
- self.destroy();
- enemyMissiles.splice(enemyMissiles.indexOf(self), 1);
- }
- };
+ var self = Container.call(this);
+ var missileGraphics = self.attachAsset('enemyMissile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ enemyMissiles.splice(enemyMissiles.indexOf(self), 1);
+ }
+ };
});
// Assets will be automatically created and loaded based on their usage in the code.
// FighterJet class
var FighterJet = Container.expand(function () {
- var self = Container.call(this);
- var jetGraphics = self.attachAsset('fighterJet', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- // Update logic for the fighter jet
- };
- self.shoot = function () {
- if (heroMissiles.length < 4) {
- var missile = new HeroMissile();
- missile.x = self.x;
- missile.y = self.y - jetGraphics.height / 2;
- heroMissiles.push(missile);
- game.addChild(missile);
- }
- };
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('fighterJet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ // Update logic for the fighter jet
+ };
+ self.shoot = function () {
+ if (heroMissiles.length < 4) {
+ var missile = new HeroMissile();
+ missile.x = self.x;
+ missile.y = self.y - jetGraphics.height / 2;
+ heroMissiles.push(missile);
+ game.addChild(missile);
+ }
+ };
});
// HeroMissile class
var HeroMissile = Container.expand(function () {
- var self = Container.call(this);
- var missileGraphics = self.attachAsset('heroMissile', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = -15;
- self.update = function () {
- self.y += self.speed;
- if (self.y < -50) {
- self.destroy();
- heroMissiles.splice(heroMissiles.indexOf(self), 1);
- }
- };
+ var self = Container.call(this);
+ var missileGraphics = self.attachAsset('heroMissile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -15;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y < -50) {
+ self.destroy();
+ heroMissiles.splice(heroMissiles.indexOf(self), 1);
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var fighterJet = game.addChild(new FighterJet());
fighterJet.x = 2048 / 2;
fighterJet.y = 2732 - 200;
var heroMissiles = [];
var aliens = [];
var enemyMissiles = [];
// Handle game move events
game.move = function (x, y, obj) {
- fighterJet.x = x;
- fighterJet.y = y;
+ fighterJet.x = x;
+ fighterJet.y = y;
};
// Handle game down events
game.down = function (x, y, obj) {
- fighterJet.shoot();
+ fighterJet.shoot();
};
// Game update loop
game.update = function () {
- // Update all missiles
- heroMissiles.forEach(function (missile) {
- missile.update();
- });
- enemyMissiles.forEach(function (missile) {
- missile.update();
- });
- // Update all aliens
- aliens.forEach(function (alien) {
- alien.update();
- if (Math.random() < 0.01) {
- alien.shoot();
- }
- });
- // Spawn new aliens
- if (LK.ticks % 60 == 0) {
- var alien = new Alien();
- alien.x = Math.random() * 2048;
- alien.y = -50;
- aliens.push(alien);
- game.addChild(alien);
- }
+ // Update all missiles
+ heroMissiles.forEach(function (missile) {
+ missile.update();
+ });
+ enemyMissiles.forEach(function (missile) {
+ missile.update();
+ });
+ // Update all aliens
+ aliens.forEach(function (alien) {
+ alien.update();
+ if (Math.random() < 0.01) {
+ alien.shoot();
+ }
+ });
+ // Spawn new aliens
+ if (LK.ticks % 60 == 0) {
+ var alien = new Alien();
+ alien.x = Math.random() * 2048;
+ alien.y = -50;
+ aliens.push(alien);
+ game.addChild(alien);
+ }
};
\ No newline at end of file
It looks like a bright green space invader. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a While missile, with a red top that is pointing downwards. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An f18 but vertical with the cockpit facing up. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.