var StarField = Container.expand(function () { var self = Container.call(this); self.stars = []; var numberOfStars = 300; for (var i = 0; i < numberOfStars; i++) { var star = LK.getAsset('star', 'Star'); star.anchor.set(0.5, 0.5); star.x = Math.random() * 2048; star.y = Math.random() * 2732; star.speed = Math.random() * 2 + 0.5; star.alpha = Math.random() * 0.5 + 0.5; self.addChild(star); self.stars.push(star); } self.update = function () { for (var i = 0; i < self.stars.length; i++) { var star = self.stars[i]; star.y += star.speed; if (star.y > 2732) { star.y -= 2732; } } }; }); var Hero = Container.expand(function () { var self = Container.call(this); self.doubleCannon = false; self.doubleCannonPowerUpCount = 0; var heroGraphics = LK.getAsset('hero', 'Hero Space Ship'); heroGraphics.anchor.set(0.5, 0.5); self.healthBar = new HealthBar(100); self.healthBar.y = -heroGraphics.height / 2 - self.healthBar.height - 5; self.healthBar.x = -self.healthBar.width / 2; self.addChild(self.healthBar); self.addChild(heroGraphics); self.moveTowards = function (target, speed) { var dx = target.x - self.x; var dy = target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > speed) { self.x += dx * speed / distance; self.y += dy * speed / distance; } else { self.x = target.x; self.y = target.y; } }; self.fireBullet = function () { if (self.doubleCannon) { var bullet1 = new Bullet(); bullet1.x = self.x - heroGraphics.width / 4; bullet1.y = self.y - heroGraphics.height / 2; var bullet2 = new Bullet(); bullet2.x = self.x + heroGraphics.width / 4; bullet2.y = self.y - heroGraphics.height / 2; return [bullet1, bullet2]; } else { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - heroGraphics.height / 2; return [bullet]; } }; }); var Enemy = Container.expand(function (isBoss, enemyType) { var self = Container.call(this); isBoss = isBoss || false; enemyType = enemyType || 'enemy1'; var enemyGraphics; if (isBoss) { enemyGraphics = LK.getAsset('boss', 'Boss Space Ship'); } else { switch (enemyType) { case 'enemy1': enemyGraphics = LK.getAsset('enemy1', 'Enemy Space Ship 1'); break; case 'enemy2': enemyGraphics = LK.getAsset('enemy2', 'Enemy Space Ship 2'); break; case 'enemy3': enemyGraphics = LK.getAsset('enemy3', 'Enemy Space Ship 3'); break; case 'enemy4': enemyGraphics = LK.getAsset('enemy4', 'Enemy Space Ship 4'); break; case 'enemy5': enemyGraphics = LK.getAsset('enemy5', 'Enemy Space Ship 5'); break; default: enemyGraphics = LK.getAsset('enemy1', 'Enemy Space Ship 1'); } } enemyGraphics.anchor.set(0.5, 0.5); self.healthBar = new HealthBar(isBoss ? 500 : 50); self.healthBar.y = -enemyGraphics.height / 2 - self.healthBar.height - 5; self.healthBar.x = -self.healthBar.width / 2; self.addChild(self.healthBar); self.addChild(enemyGraphics); self.state = "flyingIntoScreen"; self.flyInY = isBoss ? 2732 / 4 : Math.random() * (2732 / 2 - 100) + 50; self.angle = 0; self.shootCounter = Math.random() * 100; self.shoot = function (heroX, heroY, container) { var dx = heroX - self.x; var dy = heroY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); var speedMultiplier = 1 + container.score * 0.001; var vx = 7 * speedMultiplier * dx / distance; var vy = 7 * speedMultiplier * dy / distance; var enemyBullet = isBoss ? new BossBullet(vx, vy) : new EnemyBullet(vx, vy); enemyBullet.x = self.x; enemyBullet.y = self.y + enemyGraphics.height / 2; return enemyBullet; }; self.move = function (speed) { if (self.state === "flyingIntoScreen") { self.y += speed; if (self.y >= self.flyInY) { self.state = "circularPattern"; } } else if (self.state === "circularPattern") { self.angle += 0.025; self.x += Math.cos(self.angle) * speed; self.y += Math.sin(2 * self.angle) * speed * 0.5; } }; }); var BossBullet = Container.expand(function (vx, vy) { var self = Container.call(this); var bulletGraphics = LK.getAsset('bossBullet', 'Boss Bullet'); bulletGraphics.anchor.set(0.5, 0.5); self.addChild(bulletGraphics); self.vx = vx; self.vy = vy; self.move = function () { self.x += self.vx; self.y += self.vy; }; }); var EnemyBullet = Container.expand(function (vx, vy) { var self = Container.call(this); var bulletGraphics = LK.getAsset('enemyBullet', 'Enemy Bullet'); bulletGraphics.anchor.set(0.5, 0.5); self.addChild(bulletGraphics); self.vx = vx; self.vy = vy; self.move = function () { self.x += self.vx; self.y += self.vy; }; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = LK.getAsset('bullet', 'Bullet'); bulletGraphics.anchor.set(0.5, 0.5); self.addChild(bulletGraphics); }); var HealthBar = Container.expand(function (maxHealth) { var self = Container.call(this); self.maxHealth = maxHealth; self.currentHealth = maxHealth; self.isDead = function () { return self.currentHealth <= 0; }; self.bar = LK.getAsset('healthBar', 'Health Bar', 0, 0); self.bar.width = maxHealth === 500 ? 400 : 100; self.bar.height = maxHealth === 500 ? 20 : 10; self.addChild(self.bar); self.updateHealth = function (health) { self.currentHealth = health; self.bar.scale.x = self.currentHealth / self.maxHealth; }; }); var PowerUp = Container.expand(function (type) { var self = Container.call(this); self.type = type; var powerUpGraphics = self.type === 'doubleCannon' ? LK.getAsset('doubleCannonPowerUp', 'Double Cannon Power Up') : LK.getAsset('powerUp', 'Power Up'); powerUpGraphics.anchor.set(0.5, 0.5); self.addChild(powerUpGraphics); self.speed = 3; self.move = function () { self.y += self.speed; }; }); var Game = Container.expand(function () { var self = Container.call(this); var scoreText = new Text2('0', { size: 150, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); scoreText.anchor.set(.5, 0); LK.gui.top.addChild(scoreText); self.powerUpIcons = new Container(); self.powerUpIcons.x = 2048 - 100; self.powerUpIcons.y = 2732 - 100; self.addChild(self.powerUpIcons); var starField = stage.addChild(new StarField()); self.score = 0; var hero = self.addChild(new Hero()); hero.x = 1024; hero.y = 2420; var enemies = []; var bullets = []; var enemyBullets = []; var spawnEnemy = function (x, y, isBoss, enemyType) { var enemy = new Enemy(isBoss, enemyType); enemy.x = x; enemy.y = y; self.addChild(enemy); enemies.push(enemy); }; var fireBullet = function () { var bullet = hero.fireBullet(); self.addChild(bullet); bullets.push(bullet); }; var currentWave = 1; var spawnWave = function () { var enemyType = 'enemy' + ((currentWave - 1) % 5 + 1); for (var i = 0; i < 5 + Math.floor(currentWave / 2); i++) { var x = Math.random() * (2048 - 100) + 50; spawnEnemy(x, -100, false, enemyType); } }; var spawnPowerUp = function () { var x = Math.random() * (2048 - 100) + 50; var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default'); powerUp.x = x; powerUp.y = -100; self.addChild(powerUp); powerUps.push(powerUp); }; var powerUps = []; var checkPowerUpCollision = function () { for (var i = 0; i < powerUps.length; i++) { var powerUp = powerUps[i]; if (hero.intersects(powerUp)) { self.removeChild(powerUp); powerUps.splice(i, 1); if (powerUp.type === 'doubleCannon') { hero.doubleCannon = true; hero.doubleCannonPowerUpCount++; var powerUpIcon = LK.getAsset('doubleCannonPowerUp', 'Double Cannon Power Up'); powerUpIcon.anchor.set(0.5, 0.5); powerUpIcon.x = -85 * self.powerUpIcons.children.length; self.powerUpIcons.addChild(powerUpIcon); LK.setTimeout(function () { hero.doubleCannonPowerUpCount--; if (hero.doubleCannonPowerUpCount === 0) { hero.doubleCannon = false; } self.powerUpIcons.removeChild(powerUpIcon); self.powerUpIcons.children.forEach(function (icon, index) { icon.x = -50 * index; }); }, 15000); } else { heroSpeed *= 2; var powerUpIcon = LK.getAsset('powerUp', 'Power Up'); powerUpIcon.anchor.set(0.5, 0.5); powerUpIcon.x = -50 * self.powerUpIcons.children.length; self.powerUpIcons.addChild(powerUpIcon); LK.setTimeout(function () { heroSpeed /= 2; self.powerUpIcons.removeChild(powerUpIcon); self.powerUpIcons.children.forEach(function (icon, index) { icon.x = -50 * index; }); }, 15000); } } } }; spawnWave(); currentWave++; var spawnBoss = function () { var x = 1024; var y = -100; spawnEnemy(x, y, true, 'boss'); }; var autoFire = LK.setInterval(function () { var bulletsFired = hero.fireBullet(); bulletsFired.forEach(function (bullet) { self.addChild(bullet); bullets.push(bullet); }); }, 600); var targetPosition = { x: hero.x, y: hero.y }; stage.on('move', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); targetPosition.x = pos.x; targetPosition.y = pos.y; }); var heroSpeed = 15; function resetGame() { bullets.forEach(function (bullet) { self.removeChild(bullet); }); enemyBullets.forEach(function (bullet) { self.removeChild(bullet); }); enemies.forEach(function (enemy) { self.removeChild(enemy); }); bullets = []; enemyBullets = []; enemies = []; hero.x = 1024; hero.y = 2420; hero.healthBar.updateHealth(hero.healthBar.maxHealth); self.score = 0; currentWave = 1; spawnWave(); } LK.on('tick', function () { hero.moveTowards(targetPosition, heroSpeed); hero.x = Math.min(Math.max(hero.x, 0), 2048); hero.y = Math.min(Math.max(hero.y, 0), 2732); }); LK.on('tick', function () { starField.update(); for (var i = 0; i < powerUps.length; i++) { powerUps[i].move(); if (powerUps[i].y > 2732 || powerUps[i].x < 0 || powerUps[i].x > 2048) { self.removeChild(powerUps[i]); powerUps.splice(i, 1); i--; } } checkPowerUpCollision(); if (Math.random() < 0.001) { spawnPowerUp(); } for (var i = 0; i < enemies.length; i++) { enemies[i].move(5 + self.score * 0.001); } for (var i = 0; i < enemies.length; i++) { enemies[i].move(5); enemies[i].shootCounter--; if (enemies[i].shootCounter <= 0) { var enemyBullet = enemies[i].shoot(hero.x, hero.y, self); self.addChild(enemyBullet); enemyBullets.push(enemyBullet); enemies[i].shootCounter = (enemies[i].isBoss ? 50 : 100) + Math.random() * 100; } } for (var j = 0; j < enemyBullets.length; j++) { enemyBullets[j].move(); if (enemyBullets[j].x >= hero.x - hero.width / 2 && enemyBullets[j].x <= hero.x + hero.width / 2 && enemyBullets[j].y >= hero.y - hero.height / 2 && enemyBullets[j].y <= hero.y + hero.height / 2) { hero.healthBar.updateHealth(hero.healthBar.currentHealth - 10); self.removeChild(enemyBullets[j]); enemyBullets.splice(j, 1); if (hero.healthBar.isDead()) { resetGame(); return; } } if (enemyBullets[j] && enemyBullets[j].y > 2732 + 30) { self.removeChild(enemyBullets[j]); enemyBullets.splice(j, 1); j--; } } function checkBulletCollision(bulletsArray, targetArray, onHitCallback) { for (var j = 0; j < bulletsArray.length; j++) { bulletsArray[j].y -= 10; if (bulletsArray[j].y < -30 || bulletsArray[j].y > 2732 || bulletsArray[j].x < 0 || bulletsArray[j].x > 2048) { self.removeChild(bulletsArray[j]); bulletsArray.splice(j, 1); j--; } else { for (var k = targetArray.length - 1; k >= 0; k--) { var target = targetArray[k]; if (target.intersects(bulletsArray[j])) { self.removeChild(bulletsArray[j]); bulletsArray.splice(j, 1); j--; onHitCallback(target, k); break; } } } } } checkBulletCollision(bullets, enemies, function (enemy, index) { enemy.healthBar.updateHealth(enemy.healthBar.currentHealth - 10); if (enemy.healthBar.isDead()) { self.removeChild(enemy); enemies.splice(index, 1); self.score += 10 * currentWave; if (enemies.length === 0) { if (currentWave % 5 === 0) { spawnBoss(); } else { spawnWave(); } currentWave++; } scoreText.setText(self.score); } }); }); });
var StarField = Container.expand(function () {
var self = Container.call(this);
self.stars = [];
var numberOfStars = 300;
for (var i = 0; i < numberOfStars; i++) {
var star = LK.getAsset('star', 'Star');
star.anchor.set(0.5, 0.5);
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
star.speed = Math.random() * 2 + 0.5;
star.alpha = Math.random() * 0.5 + 0.5;
self.addChild(star);
self.stars.push(star);
}
self.update = function () {
for (var i = 0; i < self.stars.length; i++) {
var star = self.stars[i];
star.y += star.speed;
if (star.y > 2732) {
star.y -= 2732;
}
}
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
self.doubleCannon = false;
self.doubleCannonPowerUpCount = 0;
var heroGraphics = LK.getAsset('hero', 'Hero Space Ship');
heroGraphics.anchor.set(0.5, 0.5);
self.healthBar = new HealthBar(100);
self.healthBar.y = -heroGraphics.height / 2 - self.healthBar.height - 5;
self.healthBar.x = -self.healthBar.width / 2;
self.addChild(self.healthBar);
self.addChild(heroGraphics);
self.moveTowards = function (target, speed) {
var dx = target.x - self.x;
var dy = target.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > speed) {
self.x += dx * speed / distance;
self.y += dy * speed / distance;
} else {
self.x = target.x;
self.y = target.y;
}
};
self.fireBullet = function () {
if (self.doubleCannon) {
var bullet1 = new Bullet();
bullet1.x = self.x - heroGraphics.width / 4;
bullet1.y = self.y - heroGraphics.height / 2;
var bullet2 = new Bullet();
bullet2.x = self.x + heroGraphics.width / 4;
bullet2.y = self.y - heroGraphics.height / 2;
return [bullet1, bullet2];
} else {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
return [bullet];
}
};
});
var Enemy = Container.expand(function (isBoss, enemyType) {
var self = Container.call(this);
isBoss = isBoss || false;
enemyType = enemyType || 'enemy1';
var enemyGraphics;
if (isBoss) {
enemyGraphics = LK.getAsset('boss', 'Boss Space Ship');
} else {
switch (enemyType) {
case 'enemy1':
enemyGraphics = LK.getAsset('enemy1', 'Enemy Space Ship 1');
break;
case 'enemy2':
enemyGraphics = LK.getAsset('enemy2', 'Enemy Space Ship 2');
break;
case 'enemy3':
enemyGraphics = LK.getAsset('enemy3', 'Enemy Space Ship 3');
break;
case 'enemy4':
enemyGraphics = LK.getAsset('enemy4', 'Enemy Space Ship 4');
break;
case 'enemy5':
enemyGraphics = LK.getAsset('enemy5', 'Enemy Space Ship 5');
break;
default:
enemyGraphics = LK.getAsset('enemy1', 'Enemy Space Ship 1');
}
}
enemyGraphics.anchor.set(0.5, 0.5);
self.healthBar = new HealthBar(isBoss ? 500 : 50);
self.healthBar.y = -enemyGraphics.height / 2 - self.healthBar.height - 5;
self.healthBar.x = -self.healthBar.width / 2;
self.addChild(self.healthBar);
self.addChild(enemyGraphics);
self.state = "flyingIntoScreen";
self.flyInY = isBoss ? 2732 / 4 : Math.random() * (2732 / 2 - 100) + 50;
self.angle = 0;
self.shootCounter = Math.random() * 100;
self.shoot = function (heroX, heroY, container) {
var dx = heroX - self.x;
var dy = heroY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speedMultiplier = 1 + container.score * 0.001;
var vx = 7 * speedMultiplier * dx / distance;
var vy = 7 * speedMultiplier * dy / distance;
var enemyBullet = isBoss ? new BossBullet(vx, vy) : new EnemyBullet(vx, vy);
enemyBullet.x = self.x;
enemyBullet.y = self.y + enemyGraphics.height / 2;
return enemyBullet;
};
self.move = function (speed) {
if (self.state === "flyingIntoScreen") {
self.y += speed;
if (self.y >= self.flyInY) {
self.state = "circularPattern";
}
} else if (self.state === "circularPattern") {
self.angle += 0.025;
self.x += Math.cos(self.angle) * speed;
self.y += Math.sin(2 * self.angle) * speed * 0.5;
}
};
});
var BossBullet = Container.expand(function (vx, vy) {
var self = Container.call(this);
var bulletGraphics = LK.getAsset('bossBullet', 'Boss Bullet');
bulletGraphics.anchor.set(0.5, 0.5);
self.addChild(bulletGraphics);
self.vx = vx;
self.vy = vy;
self.move = function () {
self.x += self.vx;
self.y += self.vy;
};
});
var EnemyBullet = Container.expand(function (vx, vy) {
var self = Container.call(this);
var bulletGraphics = LK.getAsset('enemyBullet', 'Enemy Bullet');
bulletGraphics.anchor.set(0.5, 0.5);
self.addChild(bulletGraphics);
self.vx = vx;
self.vy = vy;
self.move = function () {
self.x += self.vx;
self.y += self.vy;
};
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = LK.getAsset('bullet', 'Bullet');
bulletGraphics.anchor.set(0.5, 0.5);
self.addChild(bulletGraphics);
});
var HealthBar = Container.expand(function (maxHealth) {
var self = Container.call(this);
self.maxHealth = maxHealth;
self.currentHealth = maxHealth;
self.isDead = function () {
return self.currentHealth <= 0;
};
self.bar = LK.getAsset('healthBar', 'Health Bar', 0, 0);
self.bar.width = maxHealth === 500 ? 400 : 100;
self.bar.height = maxHealth === 500 ? 20 : 10;
self.addChild(self.bar);
self.updateHealth = function (health) {
self.currentHealth = health;
self.bar.scale.x = self.currentHealth / self.maxHealth;
};
});
var PowerUp = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
var powerUpGraphics = self.type === 'doubleCannon' ? LK.getAsset('doubleCannonPowerUp', 'Double Cannon Power Up') : LK.getAsset('powerUp', 'Power Up');
powerUpGraphics.anchor.set(0.5, 0.5);
self.addChild(powerUpGraphics);
self.speed = 3;
self.move = function () {
self.y += self.speed;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var scoreText = new Text2('0', {
size: 150,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
});
scoreText.anchor.set(.5, 0);
LK.gui.top.addChild(scoreText);
self.powerUpIcons = new Container();
self.powerUpIcons.x = 2048 - 100;
self.powerUpIcons.y = 2732 - 100;
self.addChild(self.powerUpIcons);
var starField = stage.addChild(new StarField());
self.score = 0;
var hero = self.addChild(new Hero());
hero.x = 1024;
hero.y = 2420;
var enemies = [];
var bullets = [];
var enemyBullets = [];
var spawnEnemy = function (x, y, isBoss, enemyType) {
var enemy = new Enemy(isBoss, enemyType);
enemy.x = x;
enemy.y = y;
self.addChild(enemy);
enemies.push(enemy);
};
var fireBullet = function () {
var bullet = hero.fireBullet();
self.addChild(bullet);
bullets.push(bullet);
};
var currentWave = 1;
var spawnWave = function () {
var enemyType = 'enemy' + ((currentWave - 1) % 5 + 1);
for (var i = 0; i < 5 + Math.floor(currentWave / 2); i++) {
var x = Math.random() * (2048 - 100) + 50;
spawnEnemy(x, -100, false, enemyType);
}
};
var spawnPowerUp = function () {
var x = Math.random() * (2048 - 100) + 50;
var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default');
powerUp.x = x;
powerUp.y = -100;
self.addChild(powerUp);
powerUps.push(powerUp);
};
var powerUps = [];
var checkPowerUpCollision = function () {
for (var i = 0; i < powerUps.length; i++) {
var powerUp = powerUps[i];
if (hero.intersects(powerUp)) {
self.removeChild(powerUp);
powerUps.splice(i, 1);
if (powerUp.type === 'doubleCannon') {
hero.doubleCannon = true;
hero.doubleCannonPowerUpCount++;
var powerUpIcon = LK.getAsset('doubleCannonPowerUp', 'Double Cannon Power Up');
powerUpIcon.anchor.set(0.5, 0.5);
powerUpIcon.x = -85 * self.powerUpIcons.children.length;
self.powerUpIcons.addChild(powerUpIcon);
LK.setTimeout(function () {
hero.doubleCannonPowerUpCount--;
if (hero.doubleCannonPowerUpCount === 0) {
hero.doubleCannon = false;
}
self.powerUpIcons.removeChild(powerUpIcon);
self.powerUpIcons.children.forEach(function (icon, index) {
icon.x = -50 * index;
});
}, 15000);
} else {
heroSpeed *= 2;
var powerUpIcon = LK.getAsset('powerUp', 'Power Up');
powerUpIcon.anchor.set(0.5, 0.5);
powerUpIcon.x = -50 * self.powerUpIcons.children.length;
self.powerUpIcons.addChild(powerUpIcon);
LK.setTimeout(function () {
heroSpeed /= 2;
self.powerUpIcons.removeChild(powerUpIcon);
self.powerUpIcons.children.forEach(function (icon, index) {
icon.x = -50 * index;
});
}, 15000);
}
}
}
};
spawnWave();
currentWave++;
var spawnBoss = function () {
var x = 1024;
var y = -100;
spawnEnemy(x, y, true, 'boss');
};
var autoFire = LK.setInterval(function () {
var bulletsFired = hero.fireBullet();
bulletsFired.forEach(function (bullet) {
self.addChild(bullet);
bullets.push(bullet);
});
}, 600);
var targetPosition = {
x: hero.x,
y: hero.y
};
stage.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
targetPosition.x = pos.x;
targetPosition.y = pos.y;
});
var heroSpeed = 15;
function resetGame() {
bullets.forEach(function (bullet) {
self.removeChild(bullet);
});
enemyBullets.forEach(function (bullet) {
self.removeChild(bullet);
});
enemies.forEach(function (enemy) {
self.removeChild(enemy);
});
bullets = [];
enemyBullets = [];
enemies = [];
hero.x = 1024;
hero.y = 2420;
hero.healthBar.updateHealth(hero.healthBar.maxHealth);
self.score = 0;
currentWave = 1;
spawnWave();
}
LK.on('tick', function () {
hero.moveTowards(targetPosition, heroSpeed);
hero.x = Math.min(Math.max(hero.x, 0), 2048);
hero.y = Math.min(Math.max(hero.y, 0), 2732);
});
LK.on('tick', function () {
starField.update();
for (var i = 0; i < powerUps.length; i++) {
powerUps[i].move();
if (powerUps[i].y > 2732 || powerUps[i].x < 0 || powerUps[i].x > 2048) {
self.removeChild(powerUps[i]);
powerUps.splice(i, 1);
i--;
}
}
checkPowerUpCollision();
if (Math.random() < 0.001) {
spawnPowerUp();
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].move(5 + self.score * 0.001);
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].move(5);
enemies[i].shootCounter--;
if (enemies[i].shootCounter <= 0) {
var enemyBullet = enemies[i].shoot(hero.x, hero.y, self);
self.addChild(enemyBullet);
enemyBullets.push(enemyBullet);
enemies[i].shootCounter = (enemies[i].isBoss ? 50 : 100) + Math.random() * 100;
}
}
for (var j = 0; j < enemyBullets.length; j++) {
enemyBullets[j].move();
if (enemyBullets[j].x >= hero.x - hero.width / 2 && enemyBullets[j].x <= hero.x + hero.width / 2 && enemyBullets[j].y >= hero.y - hero.height / 2 && enemyBullets[j].y <= hero.y + hero.height / 2) {
hero.healthBar.updateHealth(hero.healthBar.currentHealth - 10);
self.removeChild(enemyBullets[j]);
enemyBullets.splice(j, 1);
if (hero.healthBar.isDead()) {
resetGame();
return;
}
}
if (enemyBullets[j] && enemyBullets[j].y > 2732 + 30) {
self.removeChild(enemyBullets[j]);
enemyBullets.splice(j, 1);
j--;
}
}
function checkBulletCollision(bulletsArray, targetArray, onHitCallback) {
for (var j = 0; j < bulletsArray.length; j++) {
bulletsArray[j].y -= 10;
if (bulletsArray[j].y < -30 || bulletsArray[j].y > 2732 || bulletsArray[j].x < 0 || bulletsArray[j].x > 2048) {
self.removeChild(bulletsArray[j]);
bulletsArray.splice(j, 1);
j--;
} else {
for (var k = targetArray.length - 1; k >= 0; k--) {
var target = targetArray[k];
if (target.intersects(bulletsArray[j])) {
self.removeChild(bulletsArray[j]);
bulletsArray.splice(j, 1);
j--;
onHitCallback(target, k);
break;
}
}
}
}
}
checkBulletCollision(bullets, enemies, function (enemy, index) {
enemy.healthBar.updateHealth(enemy.healthBar.currentHealth - 10);
if (enemy.healthBar.isDead()) {
self.removeChild(enemy);
enemies.splice(index, 1);
self.score += 10 * currentWave;
if (enemies.length === 0) {
if (currentWave % 5 === 0) {
spawnBoss();
} else {
spawnWave();
}
currentWave++;
}
scoreText.setText(self.score);
}
});
});
});
Alien enemy, adopted to space, flying down Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Alien enemy boss, adopted to space, flying down Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Alien enemy, adopted to space, flying down Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
Hero Spaceship, flying up, single cannon in the center Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
Dark circular power up with three bright yellow arrows pointing upwards. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Dark circular power up indicating double cannons. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Create a 2D top-down view pixel art image of a bullet for a space shooter game. The bullet should be facing upward, as it will be used as a projectile fired from the hero spaceship towards enemies in the game. The design should be sleek and give off a sense of motion. Please provide the image on a white background. Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
Single alien slime bullet, round. Game Texture. In-Game asset. 2d. Pixelart. blank background. Low detail. High contrast.
Single alien boss slime bullet, round Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.