User prompt
don't use stage.width and stage.height instead use the fixed sized variables of the play area
User prompt
new Graphics(); is deprecated and we can no longer draw directly, replace it with a XS.getAssets call and remove the draw specific calls
User prompt
new Graphics(); is deprecated, replace it with a XS.getAssets call
User prompt
Make sure bullets and and powerups that exist the play area in any direction are removed
User prompt
Create a new bullet type of the boss
User prompt
Increment wave counter after the first call to spawnWave();
User prompt
Add 4 more basic enemy types. Each wave should only consist of one enemy type.
User prompt
Update spawnEnemy to have a enemy type & update all calls to spawnEnemy, to ensure type is passed along
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
If it's possible to refactor the code to be shorter and more concise, please do so. Consider: * Is there ways to use build in functions to replace large blocks of code? * Is there ways we can easily reuse code across multipe functions? * Anything else that might make the code shorter and more concise?
User prompt
Keep track of how many double cannon powerups the player have active, only remove the effect when the player has zero double cannon powerups active.
User prompt
Make boss health bar 4x as wide and twice as high
User prompt
Ensure boss always flies all the way into the screen
User prompt
Use different asset for bosses and don't scale the boss asset
User prompt
increase powerup tiling spacing to 85px
User prompt
Move powerup icons to the right position when a powerup runs out
User prompt
Do not scale the icons attached to powerUpIcons
User prompt
Do not scale the icons attached to powerUpIcons
User prompt
Show which powerups I currently have active as a tiling list of icons in the bottom right corner of the playing field.
===================================================================
--- original.js
+++ change.js
@@ -1,503 +1,409 @@
-var StarField = Container.expand(function() {
- var self = Container.call(this); //{0}
- self.stars = [];
- var numberOfStars = 300;
- //{1}
- for (var i = 0; i < numberOfStars; i++) {
- var star = XS.getAsset('star', 'Star');
- star.anchor.set(0.5, 0.5);
- star.x = Math.random() * stage.width;
- star.y = Math.random() * stage.height;
- star.speed = Math.random() * 2 + 0.5;
- star.alpha = Math.random() * 0.5 + 0.5;
- self.addChild(star);
- self.stars.push(star);
- } //{2}
- //{3}
- self.update = function() {
- for (var i = 0; i < self.stars.length; i++) {
- var star = self.stars[i];
- star.y += star.speed;
- if (star.y > stage.height) {
- star.y -= stage.height;
- } //{4}
- } //{5}
- }; //{6}
-}); //{7}
-//{8}
-var Hero = Container.expand(function() {
- var self = Container.call(this); //{9}
- self.doubleCannon = false;
- self.doubleCannonPowerUpCount = 0;
- var heroGraphics = XS.getAsset('hero', 'Hero Space Ship'); //300x300px
- 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; //{10}
- self.addChild(self.healthBar); //{11}
- self.addChild(heroGraphics);
- //{12}
- 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); //{13}
- if (distance > speed) {
- self.x += dx * speed / distance;
- self.y += dy * speed / distance;
- } else { //{14}
- self.x = target.x;
- self.y = target.y;
- } //{15}
- }; //{16}
- //{17}
- 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 { //{18}
- var bullet = new Bullet();
- bullet.x = self.x;
- bullet.y = self.y - heroGraphics.height / 2;
- return [bullet];
- } //{19}
- }; //{20}
-}); //{21}
-//{22}
-var Enemy = Container.expand(function(isBoss, enemyType) {
- var self = Container.call(this); //{23}
- isBoss = isBoss || false;
- enemyType = enemyType || 'enemy1';
- var enemyGraphics;
- if (isBoss) {
- enemyGraphics = XS.getAsset('boss', 'Boss Space Ship');
- } else { //{24}
- switch (enemyType) {
- case 'enemy1':
- enemyGraphics = XS.getAsset('enemy1', 'Enemy Space Ship 1'); //{25}
- break; //{26}
- case 'enemy2':
- enemyGraphics = XS.getAsset('enemy2', 'Enemy Space Ship 2');
- break; //{27}
- case 'enemy3':
- enemyGraphics = XS.getAsset('enemy3', 'Enemy Space Ship 3');
- break; //{28}
- case 'enemy4':
- enemyGraphics = XS.getAsset('enemy4', 'Enemy Space Ship 4');
- break; //{29}
- case 'enemy5':
- enemyGraphics = XS.getAsset('enemy5', 'Enemy Space Ship 5');
- break; //{30}
- default:
- enemyGraphics = XS.getAsset('enemy1', 'Enemy Space Ship 1'); //{31}
- } //{32}
- } //{33}
- 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; //{34}
- self.addChild(self.healthBar); //{35}
- self.addChild(enemyGraphics);
- //{36}
- self.state = "flyingIntoScreen";
- self.flyInY = isBoss ? 2732 / 4 : Math.random() * (2732 / 2 - 100) + 50;
- self.angle = 0;
- self.shootCounter = Math.random() * 100;
- //{37}
- self.shoot = function(heroX, heroY, container) {
- var dx = heroX - self.x;
- var dy = heroY - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy); //{38}
- 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;
- }; //{39}
- //{40}
- self.move = function(speed) {
- if (self.state === "flyingIntoScreen") {
- self.y += speed;
- if (self.y >= self.flyInY) {
- self.state = "circularPattern";
- } //{41}
- } 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;
- } //{42}
- }; //{43}
-}); //{44}
-//{45}
-var BossBullet = Container.expand(function(vx, vy) {
- var self = Container.call(this); //{46}
- var bulletGraphics = XS.getAsset('bossBullet', 'Boss Bullet');
- bulletGraphics.anchor.set(0.5, 0.5); //{47}
- self.addChild(bulletGraphics); //{48}
- self.vx = vx; //{49}
- self.vy = vy; //{50}
- self.move = function() { //{51}
- self.x += self.vx; //{52}
- self.y += self.vy; //{53}
- }; //{54}
-}); //{55}
-//{56}
-var EnemyBullet = Container.expand(function(vx, vy) {
- var self = Container.call(this); //{57}
- var bulletGraphics = XS.getAsset('enemyBullet', 'Enemy Bullet');
- bulletGraphics.anchor.set(0.5, 0.5); //{58}
- self.addChild(bulletGraphics); //{59}
- self.vx = vx; //{60}
- self.vy = vy; //{61}
- self.move = function() { //{62}
- self.x += self.vx; //{63}
- self.y += self.vy; //{64}
- }; //{65}
-}); //{66}
-//{67}
-var Bullet = Container.expand(function() {
- var self = Container.call(this); //{68}
- var bulletGraphics = XS.getAsset('bullet', 'Bullet');
- bulletGraphics.anchor.set(0.5, 0.5); //{69}
- self.addChild(bulletGraphics); //{70}
-}); //{71}
-//{72}
-var HealthBar = Container.expand(function(maxHealth) {
- var self = Container.call(this); //{73}
- self.maxHealth = maxHealth;
- self.currentHealth = maxHealth;
- self.isDead = function() {
- return self.currentHealth <= 0;
- }; //{74}
- //{75}
- self.bar = new Graphics();
- self.bar.beginFill(0x00FF00);
- self.bar.drawRect(0, 0, maxHealth === 500 ? 400 : 100, maxHealth === 500 ? 20 : 10);
- self.bar.endFill();
- self.addChild(self.bar);
- //{76}
- self.updateHealth = function(health) {
- self.currentHealth = health;
- self.bar.scale.x = self.currentHealth / self.maxHealth;
- }; //{77}
-}); //{78}
-//{79}
-var PowerUp = Container.expand(function(type) {
- var self = Container.call(this); //{80}
- self.type = type;
- var powerUpGraphics = self.type === 'doubleCannon' ? XS.getAsset('doubleCannonPowerUp', 'Double Cannon Power Up') : XS.getAsset('powerUp', 'Power Up');
- powerUpGraphics.anchor.set(0.5, 0.5);
- self.addChild(powerUpGraphics);
- self.speed = 3;
- self.move = function() { //{81}
- self.y += self.speed;
- }; //{82}
-}); //{83}
-//{84}
-var Game = Container.expand(function() {
- var self = Container.call(this); //{85}
- //{86}
- //{87}
- var scoreText = new Text2('0', {
- size: 150,
- font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
- fill: "#ffffff"
- }); //{88}
- scoreText.anchor.set(.5, 0);
- XS.gui.top.addChild(scoreText);
- //{89}
- self.powerUpIcons = new Container();
- self.powerUpIcons.x = 2048 - 100;
- self.powerUpIcons.y = 2732 - 100;
- self.addChild(self.powerUpIcons);
- //{90}
- var starField = stage.addChild(new StarField());
- //{91}
- // Declare score in SpaceShooter class
- self.score = 0; //{92}
- //{93}
- var hero = self.addChild(new Hero());
- hero.x = 1024; //{94}
- hero.y = 2420; //{95}
- //{96}
- var enemies = [];
- var bullets = [];
- var enemyBullets = [];
- //{97}
- 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);
- }; //{98}
- //{99}
- var fireBullet = function() {
- var bullet = hero.fireBullet();
- self.addChild(bullet); //{100}
- bullets.push(bullet); //{101}
- }; //{102}
- //{103}
- // Add a new function to spawn a wave of enemies
- 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; //{104}
- spawnEnemy(x, -100, false, enemyType);
- } //{105}
- //{106}
- }; //{107}
- //{108}
- // Add a power-up class
- //{109}
- // Add a function to spawn a power-up
- var spawnPowerUp = function() {
- var x = Math.random() * (2048 - 100) + 50; //{110}
- var powerUp = new PowerUp(Math.random() < 0.5 ? 'doubleCannon' : 'default');
- powerUp.x = x;
- powerUp.y = -100;
- self.addChild(powerUp);
- powerUps.push(powerUp);
- }; //{111}
- //{112}
- // Add a variable to store power-ups
- var powerUps = [];
- //{113}
- // Add a function to check if the hero collects a power-up
- var checkPowerUpCollision = function() {
- for (var i = 0; i < powerUps.length; i++) { //{114}
- var powerUp = powerUps[i];
- if (hero.intersects(powerUp)) {
- //{115}
- // Remove the power-up when collected
- self.removeChild(powerUp);
- powerUps.splice(i, 1); //{116}
- //{117}
- // Activate the double cannon powerup
- if (powerUp.type === 'doubleCannon') {
- hero.doubleCannon = true;
- hero.doubleCannonPowerUpCount++;
- var powerUpIcon = XS.getAsset('doubleCannonPowerUp', 'Double Cannon Power Up');
- powerUpIcon.anchor.set(0.5, 0.5); //{118}
- //{119}
- powerUpIcon.x = -85 * self.powerUpIcons.children.length;
- self.powerUpIcons.addChild(powerUpIcon); //{120}
- XS.setTimeout(function() { //{121}
- hero.doubleCannonPowerUpCount--;
- if (hero.doubleCannonPowerUpCount === 0) {
- hero.doubleCannon = false;
- } //{122}
- self.powerUpIcons.removeChild(powerUpIcon); //{123}
- self.powerUpIcons.children.forEach(function(icon, index) { //{124}
- icon.x = -50 * index; //{125}
- }); //{126}
- }, 15000); //{127}
- } else { //{128}
- heroSpeed *= 2;
- var powerUpIcon = XS.getAsset('powerUp', 'Power Up');
- powerUpIcon.anchor.set(0.5, 0.5); //{129}
- //{130}
- powerUpIcon.x = -50 * self.powerUpIcons.children.length;
- self.powerUpIcons.addChild(powerUpIcon); //{131}
- XS.setTimeout(function() { //{132}
- heroSpeed /= 2;
- self.powerUpIcons.removeChild(powerUpIcon); //{133}
- self.powerUpIcons.children.forEach(function(icon, index) { //{134}
- icon.x = -50 * index; //{135}
- }); //{136}
- }, 15000); //{137}
- } //{138}
- } //{139}
- } //{140}
- }; //{141}
- //{142}
- // Call this function to start the first wave
- spawnWave(); //{143}
- currentWave++; //{144}
- //{145}
- // Add a new function to spawn a boss enemy
- var spawnBoss = function() {
- var x = 1024;
- var y = -100;
- spawnEnemy(x, y, true, 'boss');
- }; //{146}
- //{147}
- //{148}
- var autoFire = XS.setInterval(function() {
- var bulletsFired = hero.fireBullet();
- bulletsFired.forEach(function(bullet) {
- self.addChild(bullet); //{149}
- bullets.push(bullet); //{150}
- }); //{151}
- }, 600); // Set an interval of 600ms for auto firing bullets
- //{152}
- // Add a variable to store the target position for the hero
- var targetPosition = {
- x: hero.x,
- y: hero.y
- }; //{153}
- //{154}
- // Store the new target position when the mouse moves
- stage.on('move', function(obj) {
- var event = obj.event;
- var pos = event.getLocalPosition(self);
- targetPosition.x = pos.x;
- targetPosition.y = pos.y;
- }); //{155}
- //{156}
- // Update the hero's position to move towards a fixed speed
- var heroSpeed = 15;
- // Create the function to reset the game
- function resetGame() {
- // Remove all bullets and enemy bullets from the stage
- bullets.forEach(function(bullet) {
- self.removeChild(bullet); //{157}
- }); //{158}
- enemyBullets.forEach(function(bullet) {
- self.removeChild(bullet); //{159}
- }); //{160}
- //{161}
- // Remove all enemies from the stage
- enemies.forEach(function(enemy) {
- self.removeChild(enemy); //{162}
- }); //{163}
- //{164}
- // Reset all arrays
- bullets = [];
- enemyBullets = [];
- enemies = [];
- //{165}
- // Reset hero position and health, reset score, and reset current wave number
- hero.x = 1024; //{166}
- hero.y = 2420; //{167}
- hero.healthBar.updateHealth(hero.healthBar.maxHealth);
- self.score = 0; //{168}
- currentWave = 1;
- //{169}
- // Spawn the first wave of enemies again
- spawnWave(); //{170}
- } //{171}
- //{172}
- XS.on('tick', function() { //{173}
- hero.moveTowards(targetPosition, heroSpeed);
- //{174}
- // Ensure the hero stays within the playable area
- hero.x = Math.min(Math.max(hero.x, 0), 2048);
- hero.y = Math.min(Math.max(hero.y, 0), 2732);
- }); //{175}
- //{176}
- XS.on('tick', function() { //{177}
- starField.update();
- //{178}
- // Move power-ups and check for collisions
- for (var i = 0; i < powerUps.length; i++) { //{179}
- powerUps[i].move();
- if (powerUps[i].y > stage.height || powerUps[i].x < 0 || powerUps[i].x > stage.width) {
- self.removeChild(powerUps[i]);
- powerUps.splice(i, 1); //{180}
- i--;
- } //{181}
- } //{182}
- checkPowerUpCollision();
- //{183}
- // Randomly spawn power-ups with decreased spawn rate
- if (Math.random() < 0.001) {
- spawnPowerUp();
- } //{184}
- for (var i = 0; i < enemies.length; i++) { //{185}
- enemies[i].move(5 + self.score * 0.001); // Increase enemy speed based on the player's score
- } //{186}
- //{187}
- for (var i = 0; i < enemies.length; i++) { //{188}
- enemies[i].move(5); // Use new move function
- enemies[i].shootCounter--;
- //{189}
- 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;
- } //{190}
- } //{191}
- //{192}
- for (var j = 0; j < enemyBullets.length; j++) {
- enemyBullets[j].move();
- //{193}
- // Check if an enemy bullet intersects the hero
- 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) {
- //{194}
- // Decrease hero's health and update health bar
- hero.healthBar.updateHealth(hero.healthBar.currentHealth - 10);
- //{195}
- // Remove the enemy bullet when it hits the hero
- self.removeChild(enemyBullets[j]); //{196}
- enemyBullets.splice(j, 1); //{197}
- //{198}
- // Check if Hero is dead, and if so, call the resetGame function
- if (hero.healthBar.isDead()) {
- resetGame();
- return;
- } //{199}
- } //{200}
- //{201}
- if (enemyBullets[j] && enemyBullets[j].y > stage.height + 30) {
- self.removeChild(enemyBullets[j]); //{202}
- enemyBullets.splice(j, 1); //{203}
- j--; //{204}
- } //{205}
- } //{206}
- //{207}
- 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 > stage.height || bulletsArray[j].x < 0 || bulletsArray[j].x > stage.width) {
- self.removeChild(bulletsArray[j]); //{208}
- bulletsArray.splice(j, 1); //{209}
- j--; //{210}
- } else { //{211}
- for (var k = targetArray.length - 1; k >= 0; k--) {
- var target = targetArray[k];
- if (target.intersects(bulletsArray[j])) {
- self.removeChild(bulletsArray[j]); //{212}
- bulletsArray.splice(j, 1); //{213}
- j--; //{214}
- onHitCallback(target, k);
- break; //{215}
- } //{216}
- } //{217}
- } //{218}
- } //{219}
- } //{220}
- checkBulletCollision(bullets, enemies, function(enemy, index) {
- enemy.healthBar.updateHealth(enemy.healthBar.currentHealth - 10);
- //{221}
- if (enemy.healthBar.isDead()) {
- self.removeChild(enemy); //{222}
- enemies.splice(index, 1);
- //{223}
- self.score += 10 * currentWave;
- //{224}
- if (enemies.length === 0) {
- if (currentWave % 5 === 0) {
- spawnBoss();
- } else { //{225}
- spawnWave(); //{226}
- } //{227}
- currentWave++; //{228}
- } //{229}
- //{230}
- scoreText.setText(self.score);
- } //{231}
- }); //{232}
- }); //{233}
-}); //{234}
\ No newline at end of file
+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() * stage.width;
+ star.y = Math.random() * stage.height;
+ 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 > stage.height) {
+ star.y -= stage.height;
+ }
+ }
+ };
+});
+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');
+ self.bar.beginFill(0x00FF00);
+ self.bar.drawRect(0, 0, maxHealth === 500 ? 400 : 100, maxHealth === 500 ? 20 : 10);
+ self.bar.endFill();
+ 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 > stage.height || powerUps[i].x < 0 || powerUps[i].x > stage.width) {
+ 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 > stage.height + 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 > stage.height || bulletsArray[j].x < 0 || bulletsArray[j].x > stage.width) {
+ 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.