User prompt
Modify the fireBullet method in the Hero class to shoot 5 bullets at a time
User prompt
make the spaceship shoot 3 bullets at a time
User prompt
increase the spaceshooter bullets from 1 to 3 and they should spread like at an angle apart the left to the left, the middle goes straight the right bullet to the right where the left and right spread at a slight angle as they go up into space
User prompt
make the spaceship bullets spread apart as it increases in distance
User prompt
make the spaceship shoot bullets 5 at a time
Remix started
Copy Galactic Invader (Legacy)
/**** * Classes ****/ var BossBullet = Container.expand(function (vx, vy) { var self = Container.call(this); var bulletGraphics = LK.getAsset('bossBullet', {}); 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', {}); bulletGraphics.anchor.set(0.5, 0.5); self.addChild(bulletGraphics); }); 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', {}); } else { switch (enemyType) { case 'enemy1': enemyGraphics = LK.getAsset('enemy1', {}); break; case 'enemy2': enemyGraphics = LK.getAsset('enemy2', {}); break; case 'enemy3': enemyGraphics = LK.getAsset('enemy3', {}); break; case 'enemy4': enemyGraphics = LK.getAsset('enemy4', {}); break; case 'enemy5': enemyGraphics = LK.getAsset('enemy5', {}); break; default: enemyGraphics = LK.getAsset('enemy1', {}); } } 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 EnemyBullet = Container.expand(function (vx, vy) { var self = Container.call(this); var bulletGraphics = LK.getAsset('enemyBullet', {}); 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 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', {}); 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 Hero = Container.expand(function () { var self = Container.call(this); self.doubleCannon = false; self.doubleCannonPowerUpCount = 0; var heroGraphics = LK.getAsset('hero', {}); 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 () { var bullets = []; for (var i = 0; i < 5; i++) { var bullet = new Bullet(); bullet.x = self.x + i * 20 - 40; bullet.y = self.y - heroGraphics.height / 2; bullets.push(bullet); } return bullets; }; }); var PowerUp = Container.expand(function (type) { var self = Container.call(this); self.type = type; var powerUpGraphics = self.type === 'doubleCannon' ? LK.getAsset('doubleCannonPowerUp', {}) : LK.getAsset('powerUp', {}); powerUpGraphics.anchor.set(0.5, 0.5); self.addChild(powerUpGraphics); self.speed = 3; self.move = function () { self.y += self.speed; }; }); 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.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; } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ 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); game.powerUpIcons = new Container(); game.powerUpIcons.x = 2048 - 100; game.powerUpIcons.y = 2732 - 100; game.addChild(game.powerUpIcons); var starField = game.addChild(new StarField()); game.score = 0; var hero = game.addChild(new Hero()); hero.x = 1024; hero.y = 2420; var enemies = []; var bullets = []; var enemyBullets = []; var spawnEnemy = function spawnEnemy(x, y, isBoss, enemyType) { var enemy = new Enemy(isBoss, enemyType); enemy.x = x; enemy.y = y; game.addChild(enemy); enemies.push(enemy); }; var fireBullet = function fireBullet() { var bullet = hero.fireBullet(); game.addChild(bullet); bullets.push(bullet); }; var currentWave = 1; var spawnWave = function spawnWave() { 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 spawnPowerUp() { var x = Math.random() * (2048 - 100) + 50; var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default'); powerUp.x = x; powerUp.y = -100; game.addChild(powerUp); powerUps.push(powerUp); }; var powerUps = []; var checkPowerUpCollision = function checkPowerUpCollision() { for (var i = 0; i < powerUps.length; i++) { var powerUp = powerUps[i]; if (hero.intersects(powerUp)) { game.removeChild(powerUp); powerUps.splice(i, 1); if (powerUp.type === 'doubleCannon') { hero.doubleCannon = true; hero.doubleCannonPowerUpCount++; var powerUpIcon = LK.getAsset('doubleCannonPowerUp', {}); powerUpIcon.anchor.set(0.5, 0.5); powerUpIcon.x = -85 * game.powerUpIcons.children.length; game.powerUpIcons.addChild(powerUpIcon); LK.setTimeout(function () { hero.doubleCannonPowerUpCount--; if (hero.doubleCannonPowerUpCount === 0) { hero.doubleCannon = false; } game.powerUpIcons.removeChild(powerUpIcon); game.powerUpIcons.children.forEach(function (icon, index) { icon.x = -50 * index; }); }, 15000); } else { heroSpeed *= 2; var powerUpIcon = LK.getAsset('powerUp', {}); powerUpIcon.anchor.set(0.5, 0.5); powerUpIcon.x = -50 * game.powerUpIcons.children.length; game.powerUpIcons.addChild(powerUpIcon); LK.setTimeout(function () { heroSpeed /= 2; game.powerUpIcons.removeChild(powerUpIcon); game.powerUpIcons.children.forEach(function (icon, index) { icon.x = -50 * index; }); }, 15000); } } } }; spawnWave(); currentWave++; var spawnBoss = function spawnBoss() { var x = 1024; var y = -100; spawnEnemy(x, y, true, 'boss'); }; var autoFire = LK.setInterval(function () { var bulletsFired = hero.fireBullet(); bulletsFired.forEach(function (bullet) { game.addChild(bullet); bullets.push(bullet); }); }, 600); var targetPosition = { x: hero.x, y: hero.y }; game.on('move', function (obj) { var event = obj.event; var pos = event.getLocalPosition(game); targetPosition.x = pos.x; targetPosition.y = pos.y; }); var heroSpeed = 15; function resetGame() { bullets.forEach(function (bullet) { game.removeChild(bullet); }); enemyBullets.forEach(function (bullet) { game.removeChild(bullet); }); enemies.forEach(function (enemy) { game.removeChild(enemy); }); bullets = []; enemyBullets = []; enemies = []; hero.x = 1024; hero.y = 2420; hero.healthBar.updateHealth(hero.healthBar.maxHealth); game.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) { game.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 + game.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, game); game.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); game.removeChild(enemyBullets[j]); enemyBullets.splice(j, 1); if (hero.healthBar.isDead()) { resetGame(); return; } } if (enemyBullets[j] && enemyBullets[j].y > 2732 + 30) { game.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) { game.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])) { game.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()) { game.removeChild(enemy); enemies.splice(index, 1); game.score += 10 * currentWave; if (enemies.length === 0) { if (currentWave % 5 === 0) { spawnBoss(); } else { spawnWave(); } currentWave++; } scoreText.setText(game.score); } }); });
===================================================================
--- original.js
+++ change.js
@@ -1,94 +1,51 @@
-var StarField = Container.expand(function () {
+/****
+* Classes
+****/
+var BossBullet = Container.expand(function (vx, vy) {
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 bulletGraphics = LK.getAsset('bossBullet', {});
+ 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 Hero = Container.expand(function () {
+var Bullet = 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 bulletGraphics = LK.getAsset('bullet', {});
+ bulletGraphics.anchor.set(0.5, 0.5);
+ self.addChild(bulletGraphics);
});
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');
+ enemyGraphics = LK.getAsset('boss', {});
} else {
switch (enemyType) {
case 'enemy1':
- enemyGraphics = LK.getAsset('enemy1', 'Enemy Space Ship 1');
+ enemyGraphics = LK.getAsset('enemy1', {});
break;
case 'enemy2':
- enemyGraphics = LK.getAsset('enemy2', 'Enemy Space Ship 2');
+ enemyGraphics = LK.getAsset('enemy2', {});
break;
case 'enemy3':
- enemyGraphics = LK.getAsset('enemy3', 'Enemy Space Ship 3');
+ enemyGraphics = LK.getAsset('enemy3', {});
break;
case 'enemy4':
- enemyGraphics = LK.getAsset('enemy4', 'Enemy Space Ship 4');
+ enemyGraphics = LK.getAsset('enemy4', {});
break;
case 'enemy5':
- enemyGraphics = LK.getAsset('enemy5', 'Enemy Space Ship 5');
+ enemyGraphics = LK.getAsset('enemy5', {});
break;
default:
- enemyGraphics = LK.getAsset('enemy1', 'Enemy Space Ship 1');
+ enemyGraphics = LK.getAsset('enemy1', {});
}
}
enemyGraphics.anchor.set(0.5, 0.5);
self.healthBar = new HealthBar(isBoss ? 500 : 50);
@@ -124,23 +81,11 @@
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');
+ var bulletGraphics = LK.getAsset('enemyBullet', {});
bulletGraphics.anchor.set(0.5, 0.5);
self.addChild(bulletGraphics);
self.vx = vx;
self.vy = vy;
@@ -148,261 +93,321 @@
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 = LK.getAsset('healthBar', {});
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 Hero = Container.expand(function () {
+ var self = Container.call(this);
+ self.doubleCannon = false;
+ self.doubleCannonPowerUpCount = 0;
+ var heroGraphics = LK.getAsset('hero', {});
+ 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 () {
+ var bullets = [];
+ for (var i = 0; i < 5; i++) {
+ var bullet = new Bullet();
+ bullet.x = self.x + i * 20 - 40;
+ bullet.y = self.y - heroGraphics.height / 2;
+ bullets.push(bullet);
+ }
+ return bullets;
+ };
+});
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');
+ var powerUpGraphics = self.type === 'doubleCannon' ? LK.getAsset('doubleCannonPowerUp', {}) : LK.getAsset('powerUp', {});
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 StarField = 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);
+ self.stars = [];
+ var numberOfStars = 300;
+ for (var i = 0; i < numberOfStars; i++) {
+ var star = LK.getAsset('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 spawnPowerUp = function () {
+});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+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);
+game.powerUpIcons = new Container();
+game.powerUpIcons.x = 2048 - 100;
+game.powerUpIcons.y = 2732 - 100;
+game.addChild(game.powerUpIcons);
+var starField = game.addChild(new StarField());
+game.score = 0;
+var hero = game.addChild(new Hero());
+hero.x = 1024;
+hero.y = 2420;
+var enemies = [];
+var bullets = [];
+var enemyBullets = [];
+var spawnEnemy = function spawnEnemy(x, y, isBoss, enemyType) {
+ var enemy = new Enemy(isBoss, enemyType);
+ enemy.x = x;
+ enemy.y = y;
+ game.addChild(enemy);
+ enemies.push(enemy);
+};
+var fireBullet = function fireBullet() {
+ var bullet = hero.fireBullet();
+ game.addChild(bullet);
+ bullets.push(bullet);
+};
+var currentWave = 1;
+var spawnWave = function spawnWave() {
+ 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;
- 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);
- }
+ spawnEnemy(x, -100, false, enemyType);
+ }
+};
+var spawnPowerUp = function spawnPowerUp() {
+ var x = Math.random() * (2048 - 100) + 50;
+ var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default');
+ powerUp.x = x;
+ powerUp.y = -100;
+ game.addChild(powerUp);
+ powerUps.push(powerUp);
+};
+var powerUps = [];
+var checkPowerUpCollision = function checkPowerUpCollision() {
+ for (var i = 0; i < powerUps.length; i++) {
+ var powerUp = powerUps[i];
+ if (hero.intersects(powerUp)) {
+ game.removeChild(powerUp);
+ powerUps.splice(i, 1);
+ if (powerUp.type === 'doubleCannon') {
+ hero.doubleCannon = true;
+ hero.doubleCannonPowerUpCount++;
+ var powerUpIcon = LK.getAsset('doubleCannonPowerUp', {});
+ powerUpIcon.anchor.set(0.5, 0.5);
+ powerUpIcon.x = -85 * game.powerUpIcons.children.length;
+ game.powerUpIcons.addChild(powerUpIcon);
+ LK.setTimeout(function () {
+ hero.doubleCannonPowerUpCount--;
+ if (hero.doubleCannonPowerUpCount === 0) {
+ hero.doubleCannon = false;
+ }
+ game.powerUpIcons.removeChild(powerUpIcon);
+ game.powerUpIcons.children.forEach(function (icon, index) {
+ icon.x = -50 * index;
+ });
+ }, 15000);
+ } else {
+ heroSpeed *= 2;
+ var powerUpIcon = LK.getAsset('powerUp', {});
+ powerUpIcon.anchor.set(0.5, 0.5);
+ powerUpIcon.x = -50 * game.powerUpIcons.children.length;
+ game.powerUpIcons.addChild(powerUpIcon);
+ LK.setTimeout(function () {
+ heroSpeed /= 2;
+ game.powerUpIcons.removeChild(powerUpIcon);
+ game.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);
+};
+spawnWave();
+currentWave++;
+var spawnBoss = function spawnBoss() {
+ var x = 1024;
+ var y = -100;
+ spawnEnemy(x, y, true, 'boss');
+};
+var autoFire = LK.setInterval(function () {
+ var bulletsFired = hero.fireBullet();
+ bulletsFired.forEach(function (bullet) {
+ game.addChild(bullet);
+ bullets.push(bullet);
});
- 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--;
- }
+}, 600);
+var targetPosition = {
+ x: hero.x,
+ y: hero.y
+};
+game.on('move', function (obj) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(game);
+ targetPosition.x = pos.x;
+ targetPosition.y = pos.y;
+});
+var heroSpeed = 15;
+function resetGame() {
+ bullets.forEach(function (bullet) {
+ game.removeChild(bullet);
+ });
+ enemyBullets.forEach(function (bullet) {
+ game.removeChild(bullet);
+ });
+ enemies.forEach(function (enemy) {
+ game.removeChild(enemy);
+ });
+ bullets = [];
+ enemyBullets = [];
+ enemies = [];
+ hero.x = 1024;
+ hero.y = 2420;
+ hero.healthBar.updateHealth(hero.healthBar.maxHealth);
+ game.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) {
+ game.removeChild(powerUps[i]);
+ powerUps.splice(i, 1);
+ i--;
}
- checkPowerUpCollision();
- if (Math.random() < 0.001) {
- spawnPowerUp();
+ }
+ checkPowerUpCollision();
+ if (Math.random() < 0.001) {
+ spawnPowerUp();
+ }
+ for (var i = 0; i < enemies.length; i++) {
+ enemies[i].move(5 + game.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, game);
+ game.addChild(enemyBullet);
+ enemyBullets.push(enemyBullet);
+ enemies[i].shootCounter = (enemies[i].isBoss ? 50 : 100) + Math.random() * 100;
}
- 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);
+ game.removeChild(enemyBullets[j]);
+ enemyBullets.splice(j, 1);
+ if (hero.healthBar.isDead()) {
+ resetGame();
+ return;
}
}
- 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--;
- }
+ if (enemyBullets[j] && enemyBullets[j].y > 2732 + 30) {
+ game.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;
- }
+ }
+ 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) {
+ game.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])) {
+ game.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++;
+ }
+ checkBulletCollision(bullets, enemies, function (enemy, index) {
+ enemy.healthBar.updateHealth(enemy.healthBar.currentHealth - 10);
+ if (enemy.healthBar.isDead()) {
+ game.removeChild(enemy);
+ enemies.splice(index, 1);
+ game.score += 10 * currentWave;
+ if (enemies.length === 0) {
+ if (currentWave % 5 === 0) {
+ spawnBoss();
+ } else {
+ spawnWave();
}
- scoreText.setText(self.score);
+ currentWave++;
}
- });
+ scoreText.setText(game.score);
+ }
});
-});
+});
\ No newline at end of file
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.
a spacex starshiip rocket. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
the shape of CALIFORNIA. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Alien enemy, adopted to space, flying down 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.