User prompt
Engine particle should be under enemy in z acis
Code edit (1 edits merged)
Please save this source code
User prompt
Double size of engine particle
User prompt
Reduce enfine particles in half
User prompt
Improve game perfoance
User prompt
reduce engine particles in half
User prompt
set engine particle speed to 20 and decrease alpha by .03 per tick
User prompt
In game, add an array to keep track of particles.
User prompt
In game, add engine particles that fly out fast behind the enemy
User prompt
particle trail should be more like a thruster effect
Code edit (2 edits merged)
Please save this source code
User prompt
destroy particle trail when enemy is destroyed
User prompt
make particle trail 5 times bigger
User prompt
add a new partcile effect to show the enemy trail. this should be updated on tick and simulate speed.
Code edit (1 edits merged)
Please save this source code
User prompt
shield speed should increment the same proportion as enemy speed over time
User prompt
when an enemy is destroyed, ,assign its color tint to the particles
User prompt
in the alien class, when an alien is spawned, assign a random bright tint to it.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: alienGraphics is not defined' in or related to this line: 'alienGraphics.tint = alien.color;' Line Number: 122
User prompt
assign random bright color to enemy on spawn.
User prompt
assign different random bight color on enemy spawn
User prompt
enemies should have a random bright color
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'randomBrightColor')' in or related to this line: 'var alienGraphics = self.attachAsset('alien', {' Line Number: 44
User prompt
add bright random color to each enemy
/**** * Classes ****/ // Missile class // Alien class // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); self.particles = []; for (var i = 0; i < 20; i++) { var particle = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.2, scaleY: 0.2, alpha: 0.8 }); particle.vx = (Math.random() - 0.5) * 10; particle.vy = (Math.random() - 0.5) * 10; self.particles.push(particle); } self.update = function () { for (var i = self.particles.length - 1; i >= 0; i--) { var p = self.particles[i]; p.x += p.vx; p.y += p.vy; p.alpha -= 0.02; if (p.alpha <= 0) { p.destroy(); self.particles.splice(i, 1); } } }; }); var Alien = Container.expand(function (color) { var self = Container.call(this); var alienGraphics = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5, tint: color }); self.baseSpeed = 2; self.speedMultiplier = 1; self.move = function () { var dy = earth.y - self.y; var dx = earth.x - self.x; var angle = Math.atan2(dy, dx); var speed = self.baseSpeed * self.speedMultiplier; self.x += speed * Math.cos(angle); self.y += speed * Math.sin(angle); }; }); // Shield class var Shield = Container.expand(function () { var self = Container.call(this); self.attachAsset('shield', { anchorX: 0.5, anchorY: 0.5 }); self.orbitRadius = 200; self.orbitSpeed = 0.04; self.orbitAngle = 0; self.update = function () { self.orbitAngle += self.orbitSpeed; self.x = earth.x + self.orbitRadius * Math.cos(self.orbitAngle); self.y = earth.y + self.orbitRadius * Math.sin(self.orbitAngle); var angleToEarth = Math.atan2(earth.y - self.y, earth.x - self.x); self.rotation = angleToEarth + Math.PI / 2; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize assets used in the game. // Game variables function getRandomBrightColor() { var brightColors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; return brightColors[Math.floor(Math.random() * brightColors.length)]; } var aliens = []; var earth; var scoreTxt; var spawnAlienInterval = 120; // Frames until a new alien spawns var spawnAlienIntervalDecrement = 0.98; // Multiplier to decrease spawn interval var nextAlienSpawn = spawnAlienInterval; // Initialize Earth function initEarth() { earth = game.addChild(LK.getAsset('earth', { anchorX: 0.5, anchorY: 0.5, x: game.width / 2, y: game.height / 2 })); window.shield = game.addChild(new Shield()); window.shield.x = earth.x; window.shield.y = earth.y - window.shield.orbitRadius; } // Initialize score display function initScore() { scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); } // Spawn an alien function spawnAlien() { var alien = new Alien(getRandomBrightColor()); alien.baseSpeed += LK.getScore() * 0.1; var side = Math.floor(Math.random() * 4); switch (side) { case 0: // top alien.x = Math.random() * game.width; alien.y = -alien.height; break; case 1: // right alien.x = game.width + alien.width; alien.y = Math.random() * game.height; break; case 2: // bottom alien.x = Math.random() * game.width; alien.y = game.height + alien.height; break; case 3: // left alien.x = -alien.width; alien.y = Math.random() * game.height; break; } aliens.push(alien); game.addChild(alien); } // Check for collisions function checkCollisions() { for (var i = 0; i < aliens.length; i++) { if (window.shield.intersects(aliens[i])) { var explosion = new Explosion(); explosion.x = aliens[i].x; explosion.y = aliens[i].y; game.addChild(explosion); aliens[i].destroy(); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); aliens.splice(i, 1); } } } // Game over check function checkGameOver() { for (var i = 0; i < aliens.length; i++) { if (aliens[i].intersects(earth)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); break; } } } // Touch event to move shield game.on('down', function (obj) { window.shield.orbitSpeed *= -1; }); // Game tick event LK.on('tick', function () { // Update explosions game.children.forEach(function (child) { if (child instanceof Explosion) { child.update(); } }); // Move aliens for (var j = aliens.length - 1; j >= 0; j--) { aliens[j].move(); if (aliens[j].y > game.height + aliens[j].height) { aliens[j].destroy(); aliens.splice(j, 1); } } // Spawn aliens and update spawn interval nextAlienSpawn--; if (nextAlienSpawn <= 0) { spawnAlien(); nextAlienSpawn = spawnAlienInterval; spawnAlienInterval *= spawnAlienIntervalDecrement; } // Update shield position window.shield.update(); // Check for collisions and game over checkCollisions(); checkGameOver(); }); // Initialize game elements initEarth(); initScore();
===================================================================
--- original.js
+++ change.js
@@ -31,13 +31,14 @@
}
}
};
});
-var Alien = Container.expand(function () {
+var Alien = Container.expand(function (color) {
var self = Container.call(this);
var alienGraphics = self.attachAsset('alien', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ tint: color
});
self.baseSpeed = 2;
self.speedMultiplier = 1;
self.move = function () {
@@ -112,9 +113,9 @@
LK.gui.top.addChild(scoreTxt);
}
// Spawn an alien
function spawnAlien() {
- var alien = new Alien();
+ var alien = new Alien(getRandomBrightColor());
alien.baseSpeed += LK.getScore() * 0.1;
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0: