User prompt
shield speed should also increase progressively
User prompt
Increase shield speed progressively
Code edit (1 edits merged)
Please save this source code
User prompt
Slightly increase the shield speed when enemy increases speed
Code edit (1 edits merged)
Please save this source code
User prompt
Explosions should last double time on screen
Code edit (1 edits merged)
Please save this source code
User prompt
Have scroe appear 100 pixels lowe
User prompt
Score uodates should appear from the top
User prompt
Add score effect as it is appearing from above
User prompt
Flashscreen effect in game over should use the tint color of the enemy that hits earth
User prompt
Replace fade effect of score for appear from below
User prompt
Fix Bug: 'TypeError: LK.effects.fadeIn is not a function' in or related to this line: 'LK.effects.fadeIn(scoreTxt, 500);' Line Number: 228
User prompt
Add fadein effect to scorea
Code edit (1 edits merged)
Please save this source code
User prompt
Dont show 0 on score and add effect to score when uodated
User prompt
Make sure earth increasea it size fast and a lot when a enemy intersects with it
Code edit (1 edits merged)
Please save this source code
User prompt
After earth tint is updated, increase its size fast for 1 second and then add exposion
Code edit (1 edits merged)
Please save this source code
User prompt
When enemy intersects with earth, change tint of earth to enemy tint, and delay game over for 2 seconds
User prompt
Move engine particle 40 pixela futher from the center of the enemy
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
/**** * Classes ****/ var Particle = Container.expand(function (colorTint, speed, angle) { var self = Container.call(this); var particleGraphics = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.3, scaleY: 0.3, alpha: 0.8, tint: colorTint }); self.vx = speed * Math.cos(angle); self.vy = speed * Math.sin(angle); self.lifeSpan = 60; self.reset = function (colorTint, speed, angle) { self.vx = speed * Math.cos(angle); self.vy = speed * Math.sin(angle); self.alpha = 0.8; particleGraphics.tint = colorTint; self.lifeSpan = 60; }; self.update = function () { self.x += self.vx; self.y += self.vy; self.alpha -= 1 / self.lifeSpan; if (self.alpha <= 0) { self.visible = false; } }; return self; }); var Explosion = Container.expand(function (colorTint) { 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, tint: colorTint }); 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 () { var self = Container.call(this); var alienGraphics = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5, tint: Math.random() * 0xFFFFFF }); 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); // Emit engine particles var particleAngle = angle + Math.PI; // Opposite direction of movement if (Math.random() < 0.5) { var particleSpeed = Math.random() * 2 + 2; var particle = ParticlePool.get(self.children[0].tint, particleSpeed, particleAngle); particle.x = self.x + 40 * Math.cos(particleAngle); particle.y = self.y + 40 * Math.sin(particleAngle); game.addChild(particle); } }; }); // 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.001; 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 ****/ // Particle class // Explosion class // Alien class // Missile class // Initialize assets used in the game. // Game variables var ParticlePool = function () { var particles = []; return { get: function get(colorTint, speed, angle) { var particle = particles.find(function (p) { return !p.visible; }); if (!particle) { particle = new Particle(colorTint, speed, angle); particles.push(particle); } else { particle.reset(colorTint, speed, angle); } particle.visible = true; return particle; }, updateAll: function updateAll() { particles.forEach(function (particle) { if (particle.visible) { particle.update(); } }); } }; }(); var aliens = []; var earth; var scoreTxt; var particles = []; // Array to keep track of particles 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('', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); } // Spawn an alien function spawnAlien() { var alien = new Alien(); 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 alienColor = aliens[i].children[0].tint; var explosion = new Explosion(alienColor); 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)) { var alienColor = aliens[i].children[0].tint; LK.effects.flashScreen(alienColor, 2000); 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 and particles game.children.forEach(function (child) { if (child instanceof Explosion) { child.update(); } }); ParticlePool.updateAll(); // 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
@@ -51,9 +51,9 @@
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.01;
+ p.alpha -= 0.02;
if (p.alpha <= 0) {
p.destroy();
self.particles.splice(i, 1);
}
@@ -94,9 +94,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.orbitRadius = 200;
- self.orbitSpeed = 0.04 + LK.getScore() * 0.002;
+ self.orbitSpeed += 0.001;
self.orbitAngle = 0;
self.update = function () {
self.orbitAngle += self.orbitSpeed;
self.x = earth.x + self.orbitRadius * Math.cos(self.orbitAngle);
@@ -151,9 +151,9 @@
var earth;
var scoreTxt;
var particles = []; // Array to keep track of particles
var spawnAlienInterval = 120; // Frames until a new alien spawns
-var spawnAlienIntervalDecrement = 0.99; // Multiplier to decrease spawn interval
+var spawnAlienIntervalDecrement = 0.98; // Multiplier to decrease spawn interval
var nextAlienSpawn = spawnAlienInterval;
// Initialize Earth
function initEarth() {
earth = game.addChild(LK.getAsset('earth', {
@@ -169,10 +169,9 @@
// Initialize score display
function initScore() {
scoreTxt = new Text2('', {
size: 150,
- fill: "#ffffff",
- y: -150
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
}
@@ -217,15 +216,8 @@
game.addChild(explosion);
aliens[i].destroy();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore().toString());
- scoreTxt.y = -20;
- var scoreMoveDownInterval = LK.setInterval(function () {
- scoreTxt.y += 5;
- if (scoreTxt.y >= 0) {
- LK.clearInterval(scoreMoveDownInterval);
- }
- }, 16.67);
aliens.splice(i, 1);
}
}
}
@@ -233,9 +225,9 @@
function checkGameOver() {
for (var i = 0; i < aliens.length; i++) {
if (aliens[i].intersects(earth)) {
var alienColor = aliens[i].children[0].tint;
- LK.effects.flashScreen(alienColor, 1000);
+ LK.effects.flashScreen(alienColor, 2000);
LK.showGameOver();
break;
}
}