User prompt
add bright random color to each enemy
User prompt
particles shoudl inherit the tint of the destroyed enemy
User prompt
alien tint should be a bright color
User prompt
alien random tint should always be bright and flurescent
User prompt
make sure the alien color update on spawn is being impacted on the game
User prompt
aliens should have different random coloros
User prompt
when an alien is spawned add a random bright color as their tint
User prompt
each enemy should have a bright tint
User prompt
add a random bright color to each enemy when they are spawned
User prompt
asteriod should not increase their speed after spawned. their initial speed should be increased progressively
Code edit (2 edits merged)
Please save this source code
User prompt
explosion should should allow particles to move on tick until they are destroyed
User prompt
create a particle effect to simluate the explosion of an enemy when it is desgtroyed
User prompt
add particle effect for when a enemy is destroyed. it should be a circular explosion.
User prompt
increase aliens speed and decrease the spawn interval progressivley
User prompt
add 1 to score when alien is destroyed
User prompt
add particles effect like a thruster behind enemies
User prompt
particles shoudl be destroyed after 3 seconds
User prompt
make asteroid trail way smaller and also have different size, from bigger to smaller
User prompt
after asteroid is destroyed, it's particle trail should be destroyed by fading out in 2 seconds.
User prompt
particle trail should not use a lot of resource and be smaller
User prompt
alien trail should be 5 times smaller
User prompt
add particle effect for alien trail.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: aliens is not defined' in or related to this line: 'aliens.push(asteroid);' Line Number: 111
/**** * Classes ****/ // Missile class // Alien class var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroidGraphics = self.attachAsset('asteroid', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.move = function () { var dy = earth.y - self.y; var dx = earth.x - self.x; var angle = Math.atan2(dy, dx); self.x += self.speed * Math.cos(angle); self.y += self.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 var asteroids = []; var earth; var scoreTxt; var spawnAlienInterval = 120; // Frames until a new alien spawns 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 spawnAsteroid() { var asteroid = new Asteroid(); var side = Math.floor(Math.random() * 4); switch (side) { case 0: // top asteroid.x = Math.random() * game.width; asteroid.y = -asteroid.height; break; case 1: // right asteroid.x = game.width + asteroid.width; asteroid.y = Math.random() * game.height; break; case 2: // bottom asteroid.x = Math.random() * game.width; asteroid.y = game.height + asteroid.height; break; case 3: // left asteroid.x = -asteroid.width; asteroid.y = Math.random() * game.height; break; } asteroids.push(asteroid); game.addChild(asteroid); } // Check for collisions function checkCollisions() { for (var i = 0; i < asteroids.length; i++) { if (window.shield.intersects(asteroids[i])) { asteroids[i].destroy(); asteroids.splice(i, 1); } } } // Game over check function checkGameOver() { for (var i = 0; i < asteroids.length; i++) { if (asteroids[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 () { // Move asteroids for (var j = asteroids.length - 1; j >= 0; j--) { asteroids[j].move(); if (asteroids[j].y > game.height + asteroids[j].height) { asteroids[j].destroy(); asteroids.splice(j, 1); } } // Spawn asteroids nextAlienSpawn--; if (nextAlienSpawn <= 0) { spawnAsteroid(); nextAlienSpawn = spawnAlienInterval; } // Update shield position window.shield.update(); // Check for collisions and game over checkCollisions(); checkGameOver(); }); // Initialize game elements initEarth(); initScore();
/****
* Classes
****/
// Missile class
// Alien class
var Asteroid = Container.expand(function () {
var self = Container.call(this);
var asteroidGraphics = self.attachAsset('asteroid', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.move = function () {
var dy = earth.y - self.y;
var dx = earth.x - self.x;
var angle = Math.atan2(dy, dx);
self.x += self.speed * Math.cos(angle);
self.y += self.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
var asteroids = [];
var earth;
var scoreTxt;
var spawnAlienInterval = 120; // Frames until a new alien spawns
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 spawnAsteroid() {
var asteroid = new Asteroid();
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// top
asteroid.x = Math.random() * game.width;
asteroid.y = -asteroid.height;
break;
case 1:
// right
asteroid.x = game.width + asteroid.width;
asteroid.y = Math.random() * game.height;
break;
case 2:
// bottom
asteroid.x = Math.random() * game.width;
asteroid.y = game.height + asteroid.height;
break;
case 3:
// left
asteroid.x = -asteroid.width;
asteroid.y = Math.random() * game.height;
break;
}
asteroids.push(asteroid);
game.addChild(asteroid);
}
// Check for collisions
function checkCollisions() {
for (var i = 0; i < asteroids.length; i++) {
if (window.shield.intersects(asteroids[i])) {
asteroids[i].destroy();
asteroids.splice(i, 1);
}
}
}
// Game over check
function checkGameOver() {
for (var i = 0; i < asteroids.length; i++) {
if (asteroids[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 () {
// Move asteroids
for (var j = asteroids.length - 1; j >= 0; j--) {
asteroids[j].move();
if (asteroids[j].y > game.height + asteroids[j].height) {
asteroids[j].destroy();
asteroids.splice(j, 1);
}
}
// Spawn asteroids
nextAlienSpawn--;
if (nextAlienSpawn <= 0) {
spawnAsteroid();
nextAlienSpawn = spawnAlienInterval;
}
// Update shield position
window.shield.update();
// Check for collisions and game over
checkCollisions();
checkGameOver();
});
// Initialize game elements
initEarth();
initScore();