/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Boss enemy class
var Boss = Container.expand(function (difficulty) {
var self = Container.call(this);
var bossSprite = self.attachAsset('mutant', {
anchorX: 0.5,
anchorY: 0.5
});
// Make boss visually distinct: scale up, tint, etc.
bossSprite.scaleX = 3.2;
bossSprite.scaleY = 3.2;
bossSprite.tint = 0x8e24aa; // purple
self.radius = bossSprite.width * 1.6;
// Difficulty scaling
var diff = typeof difficulty === "number" ? difficulty : 1;
self.speed = 0.4 + diff * 0.05; // Easier: boss is slower, less scaling
self.shootTimer = 36 + Math.floor(Math.random() * 30);
self.hp = 32 + diff * 5; // Easier: boss HP scales less
// Called every tick
self.update = function () {
self.y += self.speed;
self.shootTimer--;
if (self.shootTimer <= 0) {
// If boss HP is below half, alternate between spread and ring attacks
if (self.hp <= (32 + diff * 8) / 2 && Math.random() < 0.5) {
self.shootRing(diff);
} else {
self.shoot(diff);
}
// Boss shoots more often as difficulty increases
var minShoot = Math.max(24, 60 - diff * 4);
var maxShoot = Math.max(36, 100 - diff * 6);
self.shootTimer = minShoot + Math.floor(Math.random() * (maxShoot - minShoot));
}
};
// Boss fires a spread of bullets downward (classic spread attack)
self.shoot = function (diff) {
var numBullets = 9 + Math.floor(diff / 2); // More bullets at higher difficulty
var spread = Math.PI * (0.7 + diff * 0.08); // wider spread as difficulty increases
var baseAngle = Math.PI / 2; // Downwards
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle - spread / 2 + spread / (numBullets - 1) * i;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius;
bullet.speedX = Math.cos(angle) * (15 + diff * 0.7);
bullet.speed = Math.sin(angle) * (15 + diff * 0.7);
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Boss fires a ring of bullets in all directions (harder pattern)
self.shootRing = function (diff) {
var numBullets = 16 + Math.floor(diff * 1.5); // More bullets in ring as difficulty increases
var baseAngle = Math.random() * Math.PI * 2; // randomize ring rotation
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle + Math.PI * 2 / numBullets * i;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius * 0.7;
bullet.speedX = Math.cos(angle) * (10 + diff * 0.5);
bullet.speed = Math.sin(angle) * (10 + diff * 0.5);
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Take damage
self.hit = function () {
self.hp--;
LK.getSound('mutantHit').play();
LK.effects.flashObject(self, 0xffffff, 150);
if (self.hp <= 0) {
self.destroy();
// Allow further mutant spawning after boss dies
bossSpawned = false;
return true;
}
return false;
};
return self;
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroSprite = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = heroSprite.width * 0.5;
self.shootCooldown = 0; // ticks until next shot allowed
// Called every tick
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
};
// Shoot a bullet upwards
self.shoot = function () {
if (self.shootCooldown === 0) {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - self.radius - bullet.height * 0.5;
heroBullets.push(bullet);
game.addChild(bullet);
LK.getSound('heroShoot').play();
self.shootCooldown = 12; // 12 ticks cooldown (~0.2s)
}
};
return self;
});
// Hero bullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bulletSprite.width;
self.height = bulletSprite.height;
self.speed = -22;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Mutant enemy class
var Mutant = Container.expand(function (difficulty) {
var self = Container.call(this);
var mutantSprite = self.attachAsset('mutant', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = mutantSprite.width * 0.5;
// Difficulty scaling
var diff = typeof difficulty === "number" ? difficulty : 1;
// Mutants are always fast, but their attack pattern does not scale with difficulty
self.speed = 5 + Math.random() * 2; // Fast mutants, fixed speed
self.shootTimer = 60 + Math.floor(Math.random() * 60); // Randomize first shot
self.hp = 2; // Fixed HP for easier gameplay
// Called every tick
self.update = function () {
self.y += self.speed;
self.shootTimer--;
if (self.shootTimer <= 0) {
self.shoot(diff);
// Mutants shoot more often as difficulty increases
var minShoot = Math.max(30, 90 - diff * 8);
var maxShoot = Math.max(50, 150 - diff * 10);
self.shootTimer = minShoot + Math.floor(Math.random() * (maxShoot - minShoot));
}
};
// Shoot a bullet downwards, with difficulty-based spread
self.shoot = function (diff) {
var numBullets = 1; // Always 1 bullet, no scaling
var spread = 0; // No spread
var baseAngle = Math.PI / 2; // Downwards
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius + bullet.height * 0.5;
bullet.speedX = 0;
bullet.speed = 14; // Fixed bullet speed
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Take damage
self.hit = function () {
self.hp--;
LK.getSound('mutantHit').play();
LK.effects.flashObject(self, 0xffffff, 150);
if (self.hp <= 0) {
self.destroy();
return true;
}
return false;
};
return self;
});
// Mutant bullet class
var MutantBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('mutantBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bulletSprite.width;
self.height = bulletSprite.height;
self.speed = 14;
self.update = function () {
if (typeof self.speedX === "number") {
self.x += self.speedX;
}
if (typeof self.speed === "number") {
self.y += self.speed;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Game variables
// Hero: blue box
// Mutant: green ellipse
// Hero bullet: yellow box
// Mutant bullet: red ellipse
// Sound effects
// Music
var hero;
var mutants = [];
var heroBullets = [];
var mutantBullets = [];
var lastHeroX = 0,
lastHeroY = 0;
var score = 0;
var scoreTxt;
var wave = 1;
var spawnTimer = 0;
var gameOver = false;
var bossSpawned = false;
var difficultyLevel = 0; // Increases each time a boss or mutant wave is spawned
// Score display
scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Start music
LK.playMusic('bgmusic');
// Create hero
hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 350;
game.addChild(hero);
// Helper: spawn a wave of mutants
function spawnMutantWave() {
// Boss appears at score >= 100, only once per game
if (typeof bossSpawned === "undefined") {
bossSpawned = false;
}
if (score >= 100 && !bossSpawned) {
difficultyLevel++; // Increase difficulty each time boss spawns
var boss = new Boss(difficultyLevel);
boss.x = 2048 / 2;
boss.y = -220;
mutants.push(boss);
game.addChild(boss);
bossSpawned = true;
} else {
difficultyLevel++; // Increase difficulty each time a new wave spawns
var m = new Mutant(difficultyLevel);
// Spawn mutant at a more varied X position (avoid edges)
var minX = 120;
var maxX = 2048 - 120;
m.x = minX + Math.random() * (maxX - minX);
// More variety in Y spawn
m.y = -100 - Math.random() * 400;
mutants.push(m);
game.addChild(m);
wave++;
}
}
// Initial wave
spawnMutantWave();
// Touch/mouse drag controls removed -- hero is now controlled by tap-to-move
// Tap left/right half of screen to move hero horizontally by a fixed amount
game.down = function (x, y, obj) {
var minX = hero.radius + 20;
var maxX = 2048 - hero.radius - 20;
// Only move horizontally, keep Y fixed
var moveAmount = 220;
if (x < 2048 / 2) {
// Tap left half: move left
hero.x = Math.max(minX, hero.x - moveAmount);
} else {
// Tap right half: move right
hero.x = Math.min(maxX, hero.x + moveAmount);
}
};
game.move = null;
game.up = null;
// Main game loop
game.update = function () {
if (gameOver) {
return;
}
// Hero update
hero.update();
// Show fire rate level above hero
if (!hero.fireRateTxt) {
hero.fireRateTxt = new Text2('', {
size: 60,
fill: "#fff"
});
hero.fireRateTxt.anchor.set(0.5, 1);
game.addChild(hero.fireRateTxt);
}
hero.fireRateTxt.x = hero.x;
hero.fireRateTxt.y = hero.y - hero.radius - 30;
var fireRateLevel = Math.floor(score / 50);
if (fireRateLevel > 0) {
hero.fireRateTxt.setText("Lv." + (fireRateLevel + 1));
hero.fireRateTxt.visible = true;
} else {
hero.fireRateTxt.visible = false;
}
// Hero auto-shoots, fire rate improves every 50 points (min cooldown 4 ticks)
var minCooldown = 4;
var baseCooldown = 10;
var fireRateLevel = Math.floor(score / 50);
var heroCooldown = Math.max(baseCooldown - fireRateLevel * 2, minCooldown);
if (LK.ticks % heroCooldown === 0) {
hero.shoot();
}
// Mutant update
for (var i = mutants.length - 1; i >= 0; i--) {
var m = mutants[i];
m.update();
// Remove if off screen
if (m.y > 2732 + 100) {
m.destroy();
mutants.splice(i, 1);
continue;
}
// Mutant collides with hero (game over)
if (m.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('heroHit').play();
gameOver = true;
LK.showGameOver();
return;
}
}
// Hero bullets update
for (var i = heroBullets.length - 1; i >= 0; i--) {
var b = heroBullets[i];
b.update();
// Remove if off screen
if (b.y < -100) {
b.destroy();
heroBullets.splice(i, 1);
continue;
}
// Check collision with mutants
var hit = false;
for (var j = mutants.length - 1; j >= 0; j--) {
var m = mutants[j];
if (b.intersects(m)) {
b.destroy();
heroBullets.splice(i, 1);
if (m.hit()) {
// Mutant destroyed
mutants.splice(j, 1);
score += 10;
scoreTxt.setText(score);
} else {
score += 2;
scoreTxt.setText(score);
}
hit = true;
break;
}
}
if (hit) {
continue;
}
}
// Mutant bullets update
for (var i = mutantBullets.length - 1; i >= 0; i--) {
var b = mutantBullets[i];
b.update();
// Remove if off screen
if (b.y > 2732 + 100) {
b.destroy();
mutantBullets.splice(i, 1);
continue;
}
// Check collision with hero
if (b.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('heroHit').play();
b.destroy();
mutantBullets.splice(i, 1);
gameOver = true;
LK.showGameOver();
return;
}
}
// Spawn new wave if all mutants gone
if (mutants.length === 0 && spawnTimer === 0) {
spawnTimer = 40; // Wait 40 ticks before next wave
}
if (spawnTimer > 0) {
spawnTimer--;
if (spawnTimer === 0) {
spawnMutantWave();
}
}
};
// Reset game state on restart
game.on('reset', function () {
// Remove all objects
for (var i = 0; i < mutants.length; i++) {
mutants[i].destroy();
}
for (var i = 0; i < heroBullets.length; i++) {
heroBullets[i].destroy();
}
for (var i = 0; i < mutantBullets.length; i++) {
mutantBullets[i].destroy();
}
mutants = [];
heroBullets = [];
mutantBullets = [];
score = 0;
scoreTxt.setText(score);
wave = 1;
spawnTimer = 0;
gameOver = false;
bossSpawned = false;
hero.x = 2048 / 2;
hero.y = 2732 - 350;
spawnMutantWave();
LK.playMusic('bgmusic');
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Boss enemy class
var Boss = Container.expand(function (difficulty) {
var self = Container.call(this);
var bossSprite = self.attachAsset('mutant', {
anchorX: 0.5,
anchorY: 0.5
});
// Make boss visually distinct: scale up, tint, etc.
bossSprite.scaleX = 3.2;
bossSprite.scaleY = 3.2;
bossSprite.tint = 0x8e24aa; // purple
self.radius = bossSprite.width * 1.6;
// Difficulty scaling
var diff = typeof difficulty === "number" ? difficulty : 1;
self.speed = 0.4 + diff * 0.05; // Easier: boss is slower, less scaling
self.shootTimer = 36 + Math.floor(Math.random() * 30);
self.hp = 32 + diff * 5; // Easier: boss HP scales less
// Called every tick
self.update = function () {
self.y += self.speed;
self.shootTimer--;
if (self.shootTimer <= 0) {
// If boss HP is below half, alternate between spread and ring attacks
if (self.hp <= (32 + diff * 8) / 2 && Math.random() < 0.5) {
self.shootRing(diff);
} else {
self.shoot(diff);
}
// Boss shoots more often as difficulty increases
var minShoot = Math.max(24, 60 - diff * 4);
var maxShoot = Math.max(36, 100 - diff * 6);
self.shootTimer = minShoot + Math.floor(Math.random() * (maxShoot - minShoot));
}
};
// Boss fires a spread of bullets downward (classic spread attack)
self.shoot = function (diff) {
var numBullets = 9 + Math.floor(diff / 2); // More bullets at higher difficulty
var spread = Math.PI * (0.7 + diff * 0.08); // wider spread as difficulty increases
var baseAngle = Math.PI / 2; // Downwards
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle - spread / 2 + spread / (numBullets - 1) * i;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius;
bullet.speedX = Math.cos(angle) * (15 + diff * 0.7);
bullet.speed = Math.sin(angle) * (15 + diff * 0.7);
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Boss fires a ring of bullets in all directions (harder pattern)
self.shootRing = function (diff) {
var numBullets = 16 + Math.floor(diff * 1.5); // More bullets in ring as difficulty increases
var baseAngle = Math.random() * Math.PI * 2; // randomize ring rotation
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle + Math.PI * 2 / numBullets * i;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius * 0.7;
bullet.speedX = Math.cos(angle) * (10 + diff * 0.5);
bullet.speed = Math.sin(angle) * (10 + diff * 0.5);
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Take damage
self.hit = function () {
self.hp--;
LK.getSound('mutantHit').play();
LK.effects.flashObject(self, 0xffffff, 150);
if (self.hp <= 0) {
self.destroy();
// Allow further mutant spawning after boss dies
bossSpawned = false;
return true;
}
return false;
};
return self;
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroSprite = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = heroSprite.width * 0.5;
self.shootCooldown = 0; // ticks until next shot allowed
// Called every tick
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
};
// Shoot a bullet upwards
self.shoot = function () {
if (self.shootCooldown === 0) {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - self.radius - bullet.height * 0.5;
heroBullets.push(bullet);
game.addChild(bullet);
LK.getSound('heroShoot').play();
self.shootCooldown = 12; // 12 ticks cooldown (~0.2s)
}
};
return self;
});
// Hero bullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bulletSprite.width;
self.height = bulletSprite.height;
self.speed = -22;
self.update = function () {
self.y += self.speed;
};
return self;
});
// Mutant enemy class
var Mutant = Container.expand(function (difficulty) {
var self = Container.call(this);
var mutantSprite = self.attachAsset('mutant', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = mutantSprite.width * 0.5;
// Difficulty scaling
var diff = typeof difficulty === "number" ? difficulty : 1;
// Mutants are always fast, but their attack pattern does not scale with difficulty
self.speed = 5 + Math.random() * 2; // Fast mutants, fixed speed
self.shootTimer = 60 + Math.floor(Math.random() * 60); // Randomize first shot
self.hp = 2; // Fixed HP for easier gameplay
// Called every tick
self.update = function () {
self.y += self.speed;
self.shootTimer--;
if (self.shootTimer <= 0) {
self.shoot(diff);
// Mutants shoot more often as difficulty increases
var minShoot = Math.max(30, 90 - diff * 8);
var maxShoot = Math.max(50, 150 - diff * 10);
self.shootTimer = minShoot + Math.floor(Math.random() * (maxShoot - minShoot));
}
};
// Shoot a bullet downwards, with difficulty-based spread
self.shoot = function (diff) {
var numBullets = 1; // Always 1 bullet, no scaling
var spread = 0; // No spread
var baseAngle = Math.PI / 2; // Downwards
for (var i = 0; i < numBullets; i++) {
var angle = baseAngle;
var bullet = new MutantBullet();
bullet.x = self.x;
bullet.y = self.y + self.radius + bullet.height * 0.5;
bullet.speedX = 0;
bullet.speed = 14; // Fixed bullet speed
mutantBullets.push(bullet);
game.addChild(bullet);
}
LK.getSound('mutantShoot').play();
};
// Take damage
self.hit = function () {
self.hp--;
LK.getSound('mutantHit').play();
LK.effects.flashObject(self, 0xffffff, 150);
if (self.hp <= 0) {
self.destroy();
return true;
}
return false;
};
return self;
});
// Mutant bullet class
var MutantBullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('mutantBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = bulletSprite.width;
self.height = bulletSprite.height;
self.speed = 14;
self.update = function () {
if (typeof self.speedX === "number") {
self.x += self.speedX;
}
if (typeof self.speed === "number") {
self.y += self.speed;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Game variables
// Hero: blue box
// Mutant: green ellipse
// Hero bullet: yellow box
// Mutant bullet: red ellipse
// Sound effects
// Music
var hero;
var mutants = [];
var heroBullets = [];
var mutantBullets = [];
var lastHeroX = 0,
lastHeroY = 0;
var score = 0;
var scoreTxt;
var wave = 1;
var spawnTimer = 0;
var gameOver = false;
var bossSpawned = false;
var difficultyLevel = 0; // Increases each time a boss or mutant wave is spawned
// Score display
scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Start music
LK.playMusic('bgmusic');
// Create hero
hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 350;
game.addChild(hero);
// Helper: spawn a wave of mutants
function spawnMutantWave() {
// Boss appears at score >= 100, only once per game
if (typeof bossSpawned === "undefined") {
bossSpawned = false;
}
if (score >= 100 && !bossSpawned) {
difficultyLevel++; // Increase difficulty each time boss spawns
var boss = new Boss(difficultyLevel);
boss.x = 2048 / 2;
boss.y = -220;
mutants.push(boss);
game.addChild(boss);
bossSpawned = true;
} else {
difficultyLevel++; // Increase difficulty each time a new wave spawns
var m = new Mutant(difficultyLevel);
// Spawn mutant at a more varied X position (avoid edges)
var minX = 120;
var maxX = 2048 - 120;
m.x = minX + Math.random() * (maxX - minX);
// More variety in Y spawn
m.y = -100 - Math.random() * 400;
mutants.push(m);
game.addChild(m);
wave++;
}
}
// Initial wave
spawnMutantWave();
// Touch/mouse drag controls removed -- hero is now controlled by tap-to-move
// Tap left/right half of screen to move hero horizontally by a fixed amount
game.down = function (x, y, obj) {
var minX = hero.radius + 20;
var maxX = 2048 - hero.radius - 20;
// Only move horizontally, keep Y fixed
var moveAmount = 220;
if (x < 2048 / 2) {
// Tap left half: move left
hero.x = Math.max(minX, hero.x - moveAmount);
} else {
// Tap right half: move right
hero.x = Math.min(maxX, hero.x + moveAmount);
}
};
game.move = null;
game.up = null;
// Main game loop
game.update = function () {
if (gameOver) {
return;
}
// Hero update
hero.update();
// Show fire rate level above hero
if (!hero.fireRateTxt) {
hero.fireRateTxt = new Text2('', {
size: 60,
fill: "#fff"
});
hero.fireRateTxt.anchor.set(0.5, 1);
game.addChild(hero.fireRateTxt);
}
hero.fireRateTxt.x = hero.x;
hero.fireRateTxt.y = hero.y - hero.radius - 30;
var fireRateLevel = Math.floor(score / 50);
if (fireRateLevel > 0) {
hero.fireRateTxt.setText("Lv." + (fireRateLevel + 1));
hero.fireRateTxt.visible = true;
} else {
hero.fireRateTxt.visible = false;
}
// Hero auto-shoots, fire rate improves every 50 points (min cooldown 4 ticks)
var minCooldown = 4;
var baseCooldown = 10;
var fireRateLevel = Math.floor(score / 50);
var heroCooldown = Math.max(baseCooldown - fireRateLevel * 2, minCooldown);
if (LK.ticks % heroCooldown === 0) {
hero.shoot();
}
// Mutant update
for (var i = mutants.length - 1; i >= 0; i--) {
var m = mutants[i];
m.update();
// Remove if off screen
if (m.y > 2732 + 100) {
m.destroy();
mutants.splice(i, 1);
continue;
}
// Mutant collides with hero (game over)
if (m.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('heroHit').play();
gameOver = true;
LK.showGameOver();
return;
}
}
// Hero bullets update
for (var i = heroBullets.length - 1; i >= 0; i--) {
var b = heroBullets[i];
b.update();
// Remove if off screen
if (b.y < -100) {
b.destroy();
heroBullets.splice(i, 1);
continue;
}
// Check collision with mutants
var hit = false;
for (var j = mutants.length - 1; j >= 0; j--) {
var m = mutants[j];
if (b.intersects(m)) {
b.destroy();
heroBullets.splice(i, 1);
if (m.hit()) {
// Mutant destroyed
mutants.splice(j, 1);
score += 10;
scoreTxt.setText(score);
} else {
score += 2;
scoreTxt.setText(score);
}
hit = true;
break;
}
}
if (hit) {
continue;
}
}
// Mutant bullets update
for (var i = mutantBullets.length - 1; i >= 0; i--) {
var b = mutantBullets[i];
b.update();
// Remove if off screen
if (b.y > 2732 + 100) {
b.destroy();
mutantBullets.splice(i, 1);
continue;
}
// Check collision with hero
if (b.intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('heroHit').play();
b.destroy();
mutantBullets.splice(i, 1);
gameOver = true;
LK.showGameOver();
return;
}
}
// Spawn new wave if all mutants gone
if (mutants.length === 0 && spawnTimer === 0) {
spawnTimer = 40; // Wait 40 ticks before next wave
}
if (spawnTimer > 0) {
spawnTimer--;
if (spawnTimer === 0) {
spawnMutantWave();
}
}
};
// Reset game state on restart
game.on('reset', function () {
// Remove all objects
for (var i = 0; i < mutants.length; i++) {
mutants[i].destroy();
}
for (var i = 0; i < heroBullets.length; i++) {
heroBullets[i].destroy();
}
for (var i = 0; i < mutantBullets.length; i++) {
mutantBullets[i].destroy();
}
mutants = [];
heroBullets = [];
mutantBullets = [];
score = 0;
scoreTxt.setText(score);
wave = 1;
spawnTimer = 0;
gameOver = false;
bossSpawned = false;
hero.x = 2048 / 2;
hero.y = 2732 - 350;
spawnMutantWave();
LK.playMusic('bgmusic');
});