User prompt
add stars to the background
User prompt
re add color swapping'
User prompt
add a larger delay
User prompt
reset the player bullets
User prompt
they aren't destructible
User prompt
i meant the enemy bullets
User prompt
make the bullets destructible and homing
User prompt
make the enemies and bullets hurt the player
User prompt
add a delay for shooting
User prompt
fix the swapping ability
User prompt
make red only able to be hit by red bullets
User prompt
fix it
User prompt
move shoot button to left click
User prompt
change the change color button to rmb
User prompt
make blue enemies only able to be hit by blue bullets
User prompt
make the enemies only able to be damaged by bullets of their color
User prompt
now make the bullet shoot button left click
User prompt
could you swap the swap button to right click
User prompt
Please fix the bug: 'Uncaught ReferenceError: BlueBullet is not defined' in or related to this line: 'bullet = new BlueBullet();' Line Number: 79
User prompt
add the ability to swap to red bullets
User prompt
add blue enemies that are the same as the red ones
Initial prompt
Space Invaders
/**** * Classes ****/ // BlueBullet class var BlueBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('blueBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); // BlueEnemy class var BlueEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('blueEnemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732 + enemyGraphics.height) { self.destroy(); enemies.splice(enemies.indexOf(self), 1); } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732 + enemyGraphics.height) { self.destroy(); enemies.splice(enemies.indexOf(self), 1); } }; }); // EnemyBullet class var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { self.y += self.speed; if (self.y > 2732 + bulletGraphics.height) { self.destroy(); enemyBullets.splice(enemyBullets.indexOf(self), 1); } }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Hero update logic }; self.bulletColor = 'blue'; self.shoot = function () { var bullet; if (self.bulletColor === 'blue') { bullet = new BlueBullet(); } else { bullet = new RedBullet(); } bullet.x = self.x; bullet.y = self.y - heroGraphics.height / 2; game.addChild(bullet); heroBullets.push(bullet); }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); // RedBullet class var RedBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('redBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -15; self.update = function () { self.y += self.speed; if (self.y < -bulletGraphics.height) { self.destroy(); heroBullets.splice(heroBullets.indexOf(self), 1); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var hero; var heroBullets = []; var enemies = []; var enemyBullets = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize hero hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 - 200; game.addChild(hero); // Spawn enemies function spawnEnemy() { var enemy; if (Math.random() > 0.5) { enemy = new Enemy(); } else { enemy = new BlueEnemy(); } enemy.x = Math.random() * 2048; enemy.y = -enemy.height; game.addChild(enemy); enemies.push(enemy); } // Handle game updates game.update = function () { // Update hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].update(); } // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); } // Update enemy bullets for (var i = enemyBullets.length - 1; i >= 0; i--) { enemyBullets[i].update(); } // Check for collisions for (var i = heroBullets.length - 1; i >= 0; i--) { for (var j = enemies.length - 1; j >= 0; j--) { if (heroBullets[i].intersects(enemies[j])) { if (enemies[j] instanceof BlueEnemy && heroBullets[i] instanceof BlueBullet) { enemies[j].destroy(); heroBullets[i].destroy(); enemies.splice(j, 1); heroBullets.splice(i, 1); score++; scoreTxt.setText(score); break; } else if (!(enemies[j] instanceof BlueEnemy)) { enemies[j].destroy(); heroBullets[i].destroy(); enemies.splice(j, 1); heroBullets.splice(i, 1); score++; scoreTxt.setText(score); break; } } } } // Fire enemy bullets if (LK.ticks % 60 == 0) { for (var i = 0; i < enemies.length; i++) { var bullet = new EnemyBullet(); bullet.x = enemies[i].x; bullet.y = enemies[i].y + enemies[i].height / 2; game.addChild(bullet); enemyBullets.push(bullet); } } // Spawn new enemies if (LK.ticks % 120 == 0) { spawnEnemy(); } }; // Handle touch events game.down = function (x, y, obj) { hero.bulletColor = hero.bulletColor === 'blue' ? 'red' : 'blue'; hero.shoot(); }; game.move = function (x, y, obj) { hero.x = x; }; game.up = function (x, y, obj) { // No action needed on touch up };
===================================================================
--- original.js
+++ change.js
@@ -24,9 +24,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
- self.color = 'blue'; // Add color property
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + enemyGraphics.height) {
self.destroy();
@@ -41,9 +40,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
- self.color = 'red'; // Add color property
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + enemyGraphics.height) {
self.destroy();
@@ -182,16 +180,26 @@
}
// Check for collisions
for (var i = heroBullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
- if (heroBullets[i].intersects(enemies[j]) && heroBullets[i].color === enemies[j].color) {
- enemies[j].destroy();
- heroBullets[i].destroy();
- enemies.splice(j, 1);
- heroBullets.splice(i, 1);
- score++;
- scoreTxt.setText(score);
- break;
+ if (heroBullets[i].intersects(enemies[j])) {
+ if (enemies[j] instanceof BlueEnemy && heroBullets[i] instanceof BlueBullet) {
+ enemies[j].destroy();
+ heroBullets[i].destroy();
+ enemies.splice(j, 1);
+ heroBullets.splice(i, 1);
+ score++;
+ scoreTxt.setText(score);
+ break;
+ } else if (!(enemies[j] instanceof BlueEnemy)) {
+ enemies[j].destroy();
+ heroBullets[i].destroy();
+ enemies.splice(j, 1);
+ heroBullets.splice(i, 1);
+ score++;
+ scoreTxt.setText(score);
+ break;
+ }
}
}
}
// Fire enemy bullets
blue tentacle alien. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red tentacle alien. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
purple laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
RED LASER. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
blue LASER. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
spaceship, facing up. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.