User prompt
Undo the last chance
User prompt
Fix the sound bugs
User prompt
Destroy Jet when hit by enemy
User prompt
Remove health from UI
User prompt
Show players health in UI
User prompt
Destroy Jet after got hit by enemy bullets
User prompt
Fix the bug
User prompt
Spawn less enemies
User prompt
Add health items so the player can collect
User prompt
Make the enemy destroy VFX disappear after o.1 seconds
User prompt
Add enemy destroy VFX
User prompt
Bullets colliding sound
User prompt
Make enemy shoot
User prompt
Shooting sound for enemy bullet
User prompt
Fix the bug
User prompt
Enemy bullets sound
User prompt
Make the enemy shoot back
User prompt
Player can shoot
User prompt
Undo the last two changes
User prompt
Fix the bug
User prompt
Make the player shoot automatically
User prompt
Enemy can't shoot
User prompt
Make enemy Move slow
User prompt
Please fix the bug: 'TypeError: ufo.shoot is not a function' in or related to this line: 'ufo.shoot();' Line Number: 129
User prompt
Undo the last two changes
/****
* 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++;
}
// Removed the code that makes the enemy shoot once
};
// Removed the code that makes the enemy shoot
});
/****
* 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;
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.