Code edit (1 edits merged)
Please save this source code
User prompt
fireworks should spawn more particles
User prompt
add a max of 40 stars
User prompt
make the colors, gold, blue, red, pink, deep purple, green
Code edit (1 edits merged)
Please save this source code
User prompt
the random colors should be more vibrant
User prompt
stars have a random rotation
User prompt
every 10 seconds a star has a chance to twinkle
User prompt
add a max of 20 stars, make them spawn in at the start of the game instantly
User prompt
spawn stars randomly, make 3 sizes
User prompt
make the spread of the fireworks smaller
User prompt
the gravity should be less, and first the fling of the explotion should be stronger
User prompt
the firework particles should be affected by gravity
User prompt
make the spread of the fireworks smaller
User prompt
all firework trails should be spawned at the middle and also move horizontally to the place of the click
User prompt
make the trail move faster
User prompt
prevent the game from spawning the normal fireworkparticle
User prompt
the game shouldnt try to spawn firework particle
User prompt
remove all mention of the firework partivle
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: FireworkParticle1 is not defined' in this line: 'var particle = new FireworkParticle1();' Line Number: 73
Code edit (1 edits merged)
Please save this source code
User prompt
all calls to the function firework should be firework1
User prompt
the current firework class should be firework1 also rename the asset
User prompt
make the placeholders for multiple fireworks
/****
* Classes
****/
var LaunchTrail = Container.expand(function () {
var self = Container.call(this);
var trailGraphics = self.createAsset('launchTrail', 'Launch trail', 0.5, 1);
self.y = 2732;
self.x = 2048 / 2;
self.update = function () {
self.y -= 13;
if (self.y <= self.targetY) {
self.destroy();
if (self.onComplete) {
self.onComplete();
}
}
};
self.targetY = 0;
self.setTargetY = function (y) {
self.targetY = y;
};
});
// Firework particle class
var FireworkParticle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.createAsset('fireworkParticle', 'Firework particle', 0.5, 0.5);
self.color = 0xFFFFFF; // Default color white
particleGraphics.tint = self.color;
self.speedX = 0;
self.speedY = 0;
self.alpha = 1;
self.scaleX = 1;
self.scaleY = 1;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.alpha *= 0.98; // fade out more slowly
self.scaleX *= 0.99;
self.scaleY *= 0.99;
if (self.alpha < 0.05) {
self.destroy();
}
};
});
// FireworkManager class to handle multiple fireworks
var FireworkManager = Container.expand(function () {
var self = Container.call(this);
self.fireworks = [];
self.launchFirework = function (x, y) {
var firework = new Firework();
firework.explode(x, y);
self.fireworks.push(firework);
game.addChild(firework);
};
self.update = function () {
for (var i = self.fireworks.length - 1; i >= 0; i--) {
self.fireworks[i].update();
if (self.fireworks[i].particles.length === 0) {
self.fireworks[i].destroy();
self.fireworks.splice(i, 1);
}
}
};
});
// Firework class
var Firework = Container.expand(function () {
var self = Container.call(this);
self.particles = [];
self.explode = function (x, y) {
var colors = [0xFFD700, 0x0000FF, 0x800080, 0xFF00FF, 0xFF0000];
var randomColor = colors[Math.floor(Math.random() * colors.length)];
for (var i = 0; i < 50; i++) {
var particle = new FireworkParticle();
var angle = Math.random() * Math.PI * 2;
var speed = Math.random() * 8 + 4;
particle.color = randomColor; // Assign random color to particle
particle.speedX = Math.cos(angle) * speed;
particle.speedY = Math.sin(angle) * speed;
particle.x = x;
particle.y = y;
particle.createAsset('fireworkParticle', 'Firework particle', 0.5, 0.5).tint = particle.color; // Apply color tint to particle
self.particles.push(particle);
game.addChild(particle);
}
};
self.update = function () {
for (var i = self.particles.length - 1; i >= 0; i--) {
self.particles[i].update();
if (self.particles[i].alpha < 0.05) {
self.particles.splice(i, 1);
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize FireworkManager
var fireworkManager = new FireworkManager();
// Event listener for mouse or touch down
game.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var launchTrail = new LaunchTrail();
launchTrail.x = pos.x;
launchTrail.setTargetY(pos.y);
launchTrail.onComplete = function () {
fireworkManager.launchFirework(pos.x, pos.y);
};
game.addChild(launchTrail);
});
// Update function for the game
LK.on('tick', function () {
fireworkManager.update();
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof LaunchTrail) {
game.children[i].update();
}
}
});