Code edit (2 edits merged)
Please save this source code
User prompt
add alien2 and alien3 to classes section
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: HeroBullet is not defined' in or related to this line: 'b = new HeroBullet();' Line Number: 253
User prompt
Please fix the bug: 'ReferenceError: HeroBullet is not defined' in or related to this line: 'b = new HeroBullet();' Line Number: 253
User prompt
Please fix the bug: 'ReferenceError: AlienBullet is not defined' in or related to this line: 'var b = new AlienBullet();' Line Number: 272
User prompt
Please fix the bug: 'Alien is not defined' in or related to this line: 'alien = new Alien();' Line Number: 150
User prompt
Please fix the bug: 'HeroShip is not defined' in or related to this line: 'var hero = new HeroShip();' Line Number: 62
User prompt
alien2 must be defeated at 4 bullets
User prompt
At wave4 only "alien2" must spawn.
User prompt
At wave4 and wave5 make all aliens as "alien2"
User prompt
At wave4 reduce the alien number
User prompt
Alien2 must have "alien2" asset and must have same interactions and same features like "alien"
User prompt
There must be new alien type at wave 4. This alien must be called as "alien2"
User prompt
Reduce the size of coin to the size of power-up
User prompt
Coins have "coin" asset. When collecting coin, it gives additional score.
User prompt
Increase coin-drop possibility
User prompt
Add coin-drop feature to the aliens but its possibilit must be lower than power-up frequency
User prompt
Add inv button to the right bottom corner. When pressing this button, hero ship gets immortality
User prompt
Add inv button to right bottom corner. When pressing inv buton ship gets invisibility
User prompt
Remove pass button
User prompt
There must be additional score when wave is finished. This additional score must changed according to how fast you finished the wave. If spaceships reached moving zone of hero ships, there must no any additional wave finish score
User prompt
There must be maximum 10 wave at this game
User prompt
There must be pass button at right bottom corner. When pressing it, it must go to next wave
User prompt
Please fix the bug: 'TypeError: LK.effects.explosion is not a function' in or related to this line: 'LK.effects.explosion(hero.x, hero.y, {' Line Number: 397
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Alien var Alien = Container.expand(function () { var self = Container.call(this); var alien = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5 }); self.width = alien.width; self.height = alien.height; self.speedX = 0; self.speedY = 0.8; self.shootCooldown = 0; self.row = 0; self.col = 0; self.alive = true; self.hp = 2; // Aliens require 2 hits to be defeated self.update = function () { self.x += self.speedX; self.y += self.speedY; if (self.shootCooldown > 0) self.shootCooldown -= 1; }; // Flash when hit self.flash = function () { tween(self, { alpha: 0.3 }, { duration: 60, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 100 }); } }); }; return self; }); // Alien Bullet var AlienBullet = Container.expand(function () { var self = Container.call(this); var bullet = self.attachAsset('alienBullet', { anchorX: 0.5, anchorY: 0.5 }); self.width = bullet.width; self.height = bullet.height; self.speedY = 14; self.update = function () { self.y += self.speedY; }; return self; }); // Hero Bullet var HeroBullet = Container.expand(function () { var self = Container.call(this); var bullet = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.width = bullet.width; self.height = bullet.height; self.speedY = -22; self.update = function () { self.y += self.speedY; }; return self; }); // Hero Ship var HeroShip = Container.expand(function () { var self = Container.call(this); var ship = self.attachAsset('heroShip', { anchorX: 0.5, anchorY: 0.5 }); self.width = ship.width; self.height = ship.height; self.lives = 1; self.fireCooldown = 0; self.powerLevel = 1; self.invincible = false; self.invincibleTimer = 0; // Flash when hit self.flash = function () { tween(self, { alpha: 0.3 }, { duration: 80, onFinish: function onFinish() { tween(self, { alpha: 1 }, { duration: 120 }); } }); }; // Power up self.upgrade = function () { if (self.powerLevel < 3) { self.powerLevel += 1; LK.effects.flashObject(self, 0xaa66ff, 400); } }; // Invincibility after hit self.setInvincible = function (duration) { self.invincible = true; self.invincibleTimer = duration; tween(self, { alpha: 0.5 }, { duration: 100 }); }; // Called every tick self.update = function () { if (self.invincible) { self.invincibleTimer -= 1; if (self.invincibleTimer <= 0) { self.invincible = false; self.alpha = 1; } } if (self.fireCooldown > 0) self.fireCooldown -= 1; }; return self; }); // Powerup var Powerup = Container.expand(function () { var self = Container.call(this); var p = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.width = p.width; self.height = p.height; self.speedY = 40; self.update = function () { self.y += self.speedY; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Music // Sound effects // Power-up: purple ellipse // Alien bullet: red box // Hero bullet: yellow box // Alien: green ellipse // Hero ship: blue box // Game area var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; // Play music LK.playMusic('bgmusic'); // Score var score = 0; var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Wave var wave = 1; var waveTxt = new Text2('Wave 1', { size: 70, fill: 0xAAFFFF }); waveTxt.anchor.set(0.5, 0); LK.gui.top.addChild(waveTxt); waveTxt.y = 120; // Hero var hero = new HeroShip(); game.addChild(hero); hero.x = GAME_WIDTH / 2; hero.y = GAME_HEIGHT - 220; // Bullets, aliens, powerups var heroBullets = []; var alienBullets = []; var aliens = []; var powerups = []; // Dragging var dragNode = null; // Alien formation function spawnWave(waveNum) { // Remove old aliens for (var i = aliens.length - 1; i >= 0; i--) { aliens[i].destroy(); aliens.splice(i, 1); } // Formation: rows, cols, spacing var rows = Math.min(2 + waveNum, 6); var cols = Math.min(4 + waveNum * 2, 10); var spacingX = 160; var spacingY = 140; var startX = (GAME_WIDTH - (cols - 1) * spacingX) / 2; var startY = 220 + (waveNum - 1) * 30; for (var r = 0; r < rows; r++) { for (var c = 0; c < cols; c++) { var alien = new Alien(); alien.x = startX + c * spacingX; alien.y = startY + r * spacingY; alien.row = r; alien.col = c; alien.speedX = Math.sin((r * cols + c + waveNum) * 0.7) * 1.5 + (Math.random() - 0.5) * 0.5; alien.speedY = 0.7 + 0.1 * waveNum + (Math.random() - 0.5) * 0.2; alien.shootCooldown = 60 + Math.floor(Math.random() * 60); aliens.push(alien); game.addChild(alien); } } waveTxt.setText('Wave ' + waveNum); } // Powerup spawn function maybeSpawnPowerup(x, y) { if (Math.random() < 0.03) { var p = new Powerup(); p.x = x; p.y = y; powerups.push(p); game.addChild(p); } } // Fire hero bullets function fireHeroBullets() { if (hero.fireCooldown > 0) return; var b; if (hero.powerLevel === 1) { b = new HeroBullet(); b.x = hero.x; b.y = hero.y - hero.height / 2 - 10; heroBullets.push(b); game.addChild(b); } else if (hero.powerLevel === 2) { b = new HeroBullet(); b.x = hero.x - 38; b.y = hero.y - hero.height / 2 - 10; heroBullets.push(b); game.addChild(b); b = new HeroBullet(); b.x = hero.x + 38; b.y = hero.y - hero.height / 2 - 10; heroBullets.push(b); game.addChild(b); } else if (hero.powerLevel >= 3) { b = new HeroBullet(); b.x = hero.x - 60; b.y = hero.y - hero.height / 2 - 10; heroBullets.push(b); game.addChild(b); b = new HeroBullet(); b.x = hero.x; b.y = hero.y - hero.height / 2 - 10; heroBullets.push(b); game.addChild(b); b = new HeroBullet(); b.x = hero.x + 60; b.y = hero.y - hero.height / 2 - 10; heroBullets.push(b); game.addChild(b); } hero.fireCooldown = 12; LK.getSound('shoot').play(); } // Fire alien bullet function fireAlienBullet(alien) { var b = new AlienBullet(); b.x = alien.x; b.y = alien.y + alien.height / 2 + 10; alienBullets.push(b); game.addChild(b); LK.getSound('alienShoot').play(); } // Move handler (drag hero) function handleMove(x, y, obj) { if (dragNode) { // Clamp to game area, avoid top 100px (menu) var nx = Math.max(hero.width / 2, Math.min(GAME_WIDTH - hero.width / 2, x)); var ny = Math.max(GAME_HEIGHT - 600, Math.min(GAME_HEIGHT - hero.height / 2, y)); dragNode.x = nx; dragNode.y = ny; } } game.move = handleMove; game.down = function (x, y, obj) { // Only drag if touch is on hero var local = hero.toLocal(game.toGlobal({ x: x, y: y })); if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) { dragNode = hero; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragNode = null; }; // Tap to shoot game.tap = function (x, y, obj) { fireHeroBullets(); }; // Main update game.update = function () { // Hero update hero.update(); // Fire hero bullets automatically if holding if (dragNode === hero && LK.ticks % 6 === 0) { fireHeroBullets(); } // Update hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { var b = heroBullets[i]; b.update(); // Off screen if (b.y < -b.height) { b.destroy(); heroBullets.splice(i, 1); continue; } // Hit alien for (var j = aliens.length - 1; j >= 0; j--) { var a = aliens[j]; if (a.alive && b.intersects(a)) { a.flash(); a.hp -= 1; b.destroy(); heroBullets.splice(i, 1); if (a.hp <= 0) { a.alive = false; a.destroy(); aliens.splice(j, 1); score += 100; scoreTxt.setText(score); maybeSpawnPowerup(a.x, a.y); LK.getSound('explosion').play(); } break; } } } // Update alien bullets for (var i = alienBullets.length - 1; i >= 0; i--) { var b = alienBullets[i]; b.update(); if (b.y > GAME_HEIGHT + b.height) { b.destroy(); alienBullets.splice(i, 1); continue; } // Hit hero if (!hero.invincible && b.intersects(hero)) { hero.flash(); hero.setInvincible(60); b.destroy(); alienBullets.splice(i, 1); // Explosion effect at hero ship position LK.effects.flashObject(hero, 0xffe066, 700); LK.effects.flashScreen(0xff0000, 400); LK.getSound('explosion').play(); // Game over LK.showGameOver(); return; } } // Update aliens for (var i = aliens.length - 1; i >= 0; i--) { var a = aliens[i]; a.update(); // Game over if alien touches hero ship if (a.alive && !hero.invincible && a.intersects(hero)) { hero.flash(); // Explosion effect at hero ship position LK.effects.flashObject(hero, 0xffe066, 700); LK.effects.flashScreen(0xff0000, 800); LK.getSound('explosion').play(); LK.showGameOver(); return; } // Fire bullet // Reduce firing frequency: lower probability and increase cooldown if (a.shootCooldown <= 0 && Math.random() < 0.006 + 0.001 * wave) { fireAlienBullet(a); a.shootCooldown = 120 + Math.floor(Math.random() * 80); } // Off screen (bottom) if (a.y > GAME_HEIGHT - 200) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } // Bounce alien off left/right borders if (a.x - a.width / 2 <= 0 && a.speedX < 0) { a.x = a.width / 2; a.speedX = -a.speedX; } if (a.x + a.width / 2 >= GAME_WIDTH && a.speedX > 0) { a.x = GAME_WIDTH - a.width / 2; a.speedX = -a.speedX; } // Remove alien if it goes off screen at the top if (a.y < -a.height) { a.destroy(); aliens.splice(i, 1); continue; } } // Update powerups for (var i = powerups.length - 1; i >= 0; i--) { var p = powerups[i]; p.update(); if (p.y > GAME_HEIGHT + p.height) { p.destroy(); powerups.splice(i, 1); continue; } // Collect if (p.intersects(hero)) { hero.upgrade(); LK.getSound('powerup').play(); p.destroy(); powerups.splice(i, 1); } } // Next wave if (aliens.length === 0 && !game._wavePopupActive) { game._wavePopupActive = true; // Create popup if (!game._wavePopup) { game._wavePopup = new Text2("Congratulations\nGet ready for the next wave", { size: 120, fill: 0xFFFF99, align: "center" }); game._wavePopup.anchor.set(0.5, 0.5); } game._wavePopup.setText("Congratulations\nGet ready for the next wave"); game._wavePopup.x = GAME_WIDTH / 2; game._wavePopup.y = GAME_HEIGHT / 2; if (!game._wavePopup.parent) { game.addChild(game._wavePopup); } // Play popup sound LK.getSound('powerup').play(); // Hold for 2 seconds, then start next wave LK.setTimeout(function () { if (game._wavePopup && game._wavePopup.parent) { game._wavePopup.parent.removeChild(game._wavePopup); } wave += 1; spawnWave(wave); game._wavePopupActive = false; }, 2000); } }; // Start first wave spawnWave(wave); // Initial score scoreTxt.setText(score);
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Alien
var Alien = Container.expand(function () {
var self = Container.call(this);
var alien = self.attachAsset('alien', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = alien.width;
self.height = alien.height;
self.speedX = 0;
self.speedY = 0.8;
self.shootCooldown = 0;
self.row = 0;
self.col = 0;
self.alive = true;
self.hp = 2; // Aliens require 2 hits to be defeated
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.shootCooldown > 0) self.shootCooldown -= 1;
};
// Flash when hit
self.flash = function () {
tween(self, {
alpha: 0.3
}, {
duration: 60,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 100
});
}
});
};
return self;
});
// Alien Bullet
var AlienBullet = Container.expand(function () {
var self = Container.call(this);
var bullet = self.attachAsset('alienBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bullet.width;
self.height = bullet.height;
self.speedY = 14;
self.update = function () {
self.y += self.speedY;
};
return self;
});
// Hero Bullet
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bullet = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bullet.width;
self.height = bullet.height;
self.speedY = -22;
self.update = function () {
self.y += self.speedY;
};
return self;
});
// Hero Ship
var HeroShip = Container.expand(function () {
var self = Container.call(this);
var ship = self.attachAsset('heroShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = ship.width;
self.height = ship.height;
self.lives = 1;
self.fireCooldown = 0;
self.powerLevel = 1;
self.invincible = false;
self.invincibleTimer = 0;
// Flash when hit
self.flash = function () {
tween(self, {
alpha: 0.3
}, {
duration: 80,
onFinish: function onFinish() {
tween(self, {
alpha: 1
}, {
duration: 120
});
}
});
};
// Power up
self.upgrade = function () {
if (self.powerLevel < 3) {
self.powerLevel += 1;
LK.effects.flashObject(self, 0xaa66ff, 400);
}
};
// Invincibility after hit
self.setInvincible = function (duration) {
self.invincible = true;
self.invincibleTimer = duration;
tween(self, {
alpha: 0.5
}, {
duration: 100
});
};
// Called every tick
self.update = function () {
if (self.invincible) {
self.invincibleTimer -= 1;
if (self.invincibleTimer <= 0) {
self.invincible = false;
self.alpha = 1;
}
}
if (self.fireCooldown > 0) self.fireCooldown -= 1;
};
return self;
});
// Powerup
var Powerup = Container.expand(function () {
var self = Container.call(this);
var p = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = p.width;
self.height = p.height;
self.speedY = 40;
self.update = function () {
self.y += self.speedY;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Music
// Sound effects
// Power-up: purple ellipse
// Alien bullet: red box
// Hero bullet: yellow box
// Alien: green ellipse
// Hero ship: blue box
// Game area
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
// Play music
LK.playMusic('bgmusic');
// Score
var score = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Wave
var wave = 1;
var waveTxt = new Text2('Wave 1', {
size: 70,
fill: 0xAAFFFF
});
waveTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(waveTxt);
waveTxt.y = 120;
// Hero
var hero = new HeroShip();
game.addChild(hero);
hero.x = GAME_WIDTH / 2;
hero.y = GAME_HEIGHT - 220;
// Bullets, aliens, powerups
var heroBullets = [];
var alienBullets = [];
var aliens = [];
var powerups = [];
// Dragging
var dragNode = null;
// Alien formation
function spawnWave(waveNum) {
// Remove old aliens
for (var i = aliens.length - 1; i >= 0; i--) {
aliens[i].destroy();
aliens.splice(i, 1);
}
// Formation: rows, cols, spacing
var rows = Math.min(2 + waveNum, 6);
var cols = Math.min(4 + waveNum * 2, 10);
var spacingX = 160;
var spacingY = 140;
var startX = (GAME_WIDTH - (cols - 1) * spacingX) / 2;
var startY = 220 + (waveNum - 1) * 30;
for (var r = 0; r < rows; r++) {
for (var c = 0; c < cols; c++) {
var alien = new Alien();
alien.x = startX + c * spacingX;
alien.y = startY + r * spacingY;
alien.row = r;
alien.col = c;
alien.speedX = Math.sin((r * cols + c + waveNum) * 0.7) * 1.5 + (Math.random() - 0.5) * 0.5;
alien.speedY = 0.7 + 0.1 * waveNum + (Math.random() - 0.5) * 0.2;
alien.shootCooldown = 60 + Math.floor(Math.random() * 60);
aliens.push(alien);
game.addChild(alien);
}
}
waveTxt.setText('Wave ' + waveNum);
}
// Powerup spawn
function maybeSpawnPowerup(x, y) {
if (Math.random() < 0.03) {
var p = new Powerup();
p.x = x;
p.y = y;
powerups.push(p);
game.addChild(p);
}
}
// Fire hero bullets
function fireHeroBullets() {
if (hero.fireCooldown > 0) return;
var b;
if (hero.powerLevel === 1) {
b = new HeroBullet();
b.x = hero.x;
b.y = hero.y - hero.height / 2 - 10;
heroBullets.push(b);
game.addChild(b);
} else if (hero.powerLevel === 2) {
b = new HeroBullet();
b.x = hero.x - 38;
b.y = hero.y - hero.height / 2 - 10;
heroBullets.push(b);
game.addChild(b);
b = new HeroBullet();
b.x = hero.x + 38;
b.y = hero.y - hero.height / 2 - 10;
heroBullets.push(b);
game.addChild(b);
} else if (hero.powerLevel >= 3) {
b = new HeroBullet();
b.x = hero.x - 60;
b.y = hero.y - hero.height / 2 - 10;
heroBullets.push(b);
game.addChild(b);
b = new HeroBullet();
b.x = hero.x;
b.y = hero.y - hero.height / 2 - 10;
heroBullets.push(b);
game.addChild(b);
b = new HeroBullet();
b.x = hero.x + 60;
b.y = hero.y - hero.height / 2 - 10;
heroBullets.push(b);
game.addChild(b);
}
hero.fireCooldown = 12;
LK.getSound('shoot').play();
}
// Fire alien bullet
function fireAlienBullet(alien) {
var b = new AlienBullet();
b.x = alien.x;
b.y = alien.y + alien.height / 2 + 10;
alienBullets.push(b);
game.addChild(b);
LK.getSound('alienShoot').play();
}
// Move handler (drag hero)
function handleMove(x, y, obj) {
if (dragNode) {
// Clamp to game area, avoid top 100px (menu)
var nx = Math.max(hero.width / 2, Math.min(GAME_WIDTH - hero.width / 2, x));
var ny = Math.max(GAME_HEIGHT - 600, Math.min(GAME_HEIGHT - hero.height / 2, y));
dragNode.x = nx;
dragNode.y = ny;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Only drag if touch is on hero
var local = hero.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -hero.width / 2 && local.x < hero.width / 2 && local.y > -hero.height / 2 && local.y < hero.height / 2) {
dragNode = hero;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Tap to shoot
game.tap = function (x, y, obj) {
fireHeroBullets();
};
// Main update
game.update = function () {
// Hero update
hero.update();
// Fire hero bullets automatically if holding
if (dragNode === hero && LK.ticks % 6 === 0) {
fireHeroBullets();
}
// Update hero bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
var b = heroBullets[i];
b.update();
// Off screen
if (b.y < -b.height) {
b.destroy();
heroBullets.splice(i, 1);
continue;
}
// Hit alien
for (var j = aliens.length - 1; j >= 0; j--) {
var a = aliens[j];
if (a.alive && b.intersects(a)) {
a.flash();
a.hp -= 1;
b.destroy();
heroBullets.splice(i, 1);
if (a.hp <= 0) {
a.alive = false;
a.destroy();
aliens.splice(j, 1);
score += 100;
scoreTxt.setText(score);
maybeSpawnPowerup(a.x, a.y);
LK.getSound('explosion').play();
}
break;
}
}
}
// Update alien bullets
for (var i = alienBullets.length - 1; i >= 0; i--) {
var b = alienBullets[i];
b.update();
if (b.y > GAME_HEIGHT + b.height) {
b.destroy();
alienBullets.splice(i, 1);
continue;
}
// Hit hero
if (!hero.invincible && b.intersects(hero)) {
hero.flash();
hero.setInvincible(60);
b.destroy();
alienBullets.splice(i, 1);
// Explosion effect at hero ship position
LK.effects.flashObject(hero, 0xffe066, 700);
LK.effects.flashScreen(0xff0000, 400);
LK.getSound('explosion').play();
// Game over
LK.showGameOver();
return;
}
}
// Update aliens
for (var i = aliens.length - 1; i >= 0; i--) {
var a = aliens[i];
a.update();
// Game over if alien touches hero ship
if (a.alive && !hero.invincible && a.intersects(hero)) {
hero.flash();
// Explosion effect at hero ship position
LK.effects.flashObject(hero, 0xffe066, 700);
LK.effects.flashScreen(0xff0000, 800);
LK.getSound('explosion').play();
LK.showGameOver();
return;
}
// Fire bullet
// Reduce firing frequency: lower probability and increase cooldown
if (a.shootCooldown <= 0 && Math.random() < 0.006 + 0.001 * wave) {
fireAlienBullet(a);
a.shootCooldown = 120 + Math.floor(Math.random() * 80);
}
// Off screen (bottom)
if (a.y > GAME_HEIGHT - 200) {
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
return;
}
// Bounce alien off left/right borders
if (a.x - a.width / 2 <= 0 && a.speedX < 0) {
a.x = a.width / 2;
a.speedX = -a.speedX;
}
if (a.x + a.width / 2 >= GAME_WIDTH && a.speedX > 0) {
a.x = GAME_WIDTH - a.width / 2;
a.speedX = -a.speedX;
}
// Remove alien if it goes off screen at the top
if (a.y < -a.height) {
a.destroy();
aliens.splice(i, 1);
continue;
}
}
// Update powerups
for (var i = powerups.length - 1; i >= 0; i--) {
var p = powerups[i];
p.update();
if (p.y > GAME_HEIGHT + p.height) {
p.destroy();
powerups.splice(i, 1);
continue;
}
// Collect
if (p.intersects(hero)) {
hero.upgrade();
LK.getSound('powerup').play();
p.destroy();
powerups.splice(i, 1);
}
}
// Next wave
if (aliens.length === 0 && !game._wavePopupActive) {
game._wavePopupActive = true;
// Create popup
if (!game._wavePopup) {
game._wavePopup = new Text2("Congratulations\nGet ready for the next wave", {
size: 120,
fill: 0xFFFF99,
align: "center"
});
game._wavePopup.anchor.set(0.5, 0.5);
}
game._wavePopup.setText("Congratulations\nGet ready for the next wave");
game._wavePopup.x = GAME_WIDTH / 2;
game._wavePopup.y = GAME_HEIGHT / 2;
if (!game._wavePopup.parent) {
game.addChild(game._wavePopup);
}
// Play popup sound
LK.getSound('powerup').play();
// Hold for 2 seconds, then start next wave
LK.setTimeout(function () {
if (game._wavePopup && game._wavePopup.parent) {
game._wavePopup.parent.removeChild(game._wavePopup);
}
wave += 1;
spawnWave(wave);
game._wavePopupActive = false;
}, 2000);
}
};
// Start first wave
spawnWave(wave);
// Initial score
scoreTxt.setText(score);
Space ship with guns. In-Game asset. 2d. High contrast. No shadows
A green alien ship. In-Game asset. 2d. High contrast. No shadows
A navy blue alien ship. In-Game asset. 2d. High contrast. No shadows
A dark purple alien ship. In-Game asset. 2d. High contrast. No shadows
A coin having saturn logo. In-Game asset. 2d. High contrast. No shadows
A power-up logo for spaceships. In-Game asset. 2d. High contrast. No shadows
Giant bordeux ostentatious alien ship with ostentatious giant guns. Looking straightly down In-Game asset. 2d. High contrast. No shadows
red dot. In-Game asset. 2d. High contrast. No shadows
light yellow dot. In-Game asset. 2d. High contrast. No shadows
bgmusic
Music
explosion
Sound effect
alienexplosion
Sound effect
powerup
Sound effect
wavepass
Sound effect
coinsound
Sound effect
shoot
Sound effect
alienShoot
Sound effect
bossmusic
Music
bossmusic2
Music
bossexplosion
Sound effect
bossexplosion2
Sound effect
bossexplosion3
Sound effect
bossexplosion4
Sound effect
bosswin
Sound effect
rage
Sound effect
menumusic
Music
menuclick
Sound effect