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
****/
// 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.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);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var jet;
var heroBullets = [];
var ufos = [];
var score = 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();
});
// Check for collisions
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;
}
}
}
// 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;
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.