User prompt
when the background flashed do it in the same color as the firework, not a darker color
User prompt
dont use a darker color for the flash
Code edit (1 edits merged)
Please save this source code
User prompt
remove the delay between the firework exploding and the background changing
User prompt
as soon as the firework explodes, flash the background
User prompt
remove the flasheffect when a firework explodes
Code edit (2 edits merged)
Please save this source code
User prompt
disable the flash but keep the code
User prompt
get the color of the current exploding firework and make the background 1/3 of that color, for 0.5 seconds after that change it back to black
User prompt
dont use lk.flashcreen but use lk.setbackgroundcolor for the background flashing
Code edit (6 edits merged)
Please save this source code
User prompt
make the background flash longer
User prompt
when the firework explodes, the background should quickly flash with the darker version of the color of that firework
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var Star = Container.expand(function () {
var self = Container.call(this);
var sizeOptions = [0.5, 0.75, 1]; // Three sizes: small, medium, large
var size = sizeOptions[Math.floor(Math.random() * sizeOptions.length)];
var starGraphics = self.createAsset('star', 'Star graphics', 0.5, 0.5);
starGraphics.scale.set(size, size);
starGraphics.rotation = Math.random() * Math.PI * 2;
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
self.update = function () {
// Twinkle effect logic
if (LK.ticks % (10 * 60) === 0 && Math.random() < 0.5) {
LK.effects.flashObject(self, 0xFFFFFF, 300);
}
};
});
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 -= 26;
if (self.y <= self.targetY) {
self.destroy();
var firework = new Firework();
firework.explode(self.x, self.targetY);
fireworks.push(firework);
}
};
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 () {
var gravity = 0.05;
self.speedY += gravity;
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();
}
};
});
// Firework class
var Firework = Container.expand(function () {
var self = Container.call(this);
self.particles = [];
self.explode = function (x, y) {
var colors = [0xFFD700, 0x0000FF, 0xFF0000, 0xFFC0CB, 0x800080, 0x00a32c]; // gold, blue, red, pink, deep purple, green
var randomColor = colors[Math.floor(Math.random() * colors.length)];
for (var i = 0; i < 100; i++) {
var particle = new FireworkParticle();
var angle = Math.random() * Math.PI * 2;
var speed = Math.random() * 3 + 2;
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 fireworks array
var fireworks = [];
// Initialize stars array
var stars = [];
// Spawn 20 stars instantly at the start of the game
for (var i = 0; i < 20; i++) {
var star = new Star();
stars.push(star);
game.addChild(star);
}
// 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);
game.addChild(launchTrail);
});
// Update function for the game
LK.on('tick', function () {
// Spawn stars randomly, but ensure the maximum number of stars does not exceed 40
if (stars.length < 40) {
var chanceToSpawnStar = 0.1; // 10% chance to spawn a star each tick
if (Math.random() < chanceToSpawnStar) {
var star = new Star();
stars.push(star);
game.addChild(star);
}
}
for (var i = fireworks.length - 1; i >= 0; i--) {
fireworks[i].update();
if (fireworks[i].particles.length === 0) {
fireworks.splice(i, 1);
}
}
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof LaunchTrail) {
game.children[i].update();
}
}
});