User prompt
Add a menu to choose three songs
User prompt
The fireworks, upon touching the edges, must account for the miss
User prompt
The explosion sprite should be "party"
User prompt
Add an explosion effect when you touch a firework; the color of the explosion depends on the color of the firework. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'ReferenceError: spawnCounter is not defined' in or related to this line: 'spawnCounter++;' Line Number: 110
User prompt
Add a system that syncs the fireworks to the actual rhythm of the song.
Code edit (1 edits merged)
Please save this source code
User prompt
Rhythm Fireworks
Initial prompt
Fireworks fly by to the rhythm of a song, and you have to touch them; if you miss 3, you lose.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Explosion = Container.expand(function () {
var self = Container.call(this);
self.init = function (x, y, color) {
self.x = x;
self.y = y;
// Create explosion particles
var particleCount = 8;
for (var i = 0; i < particleCount; i++) {
var particle = LK.getAsset('Party', {
anchorX: 0.5,
anchorY: 0.5,
tint: color,
alpha: 0.8,
scaleX: 0.5,
scaleY: 0.5
});
// Calculate angle for radial spread
var angle = Math.PI * 2 / particleCount * i;
var vx = Math.cos(angle) * 8;
var vy = Math.sin(angle) * 8;
// Store velocity on particle
particle.vx = vx;
particle.vy = vy;
particle.life = 30;
self.addChild(particle);
}
};
self.update = function () {
for (var i = self.children.length - 1; i >= 0; i--) {
var particle = self.children[i];
if (particle) {
particle.x += particle.vx;
particle.y += particle.vy;
particle.life--;
particle.alpha = particle.life / 30 * 0.8;
if (particle.life <= 0) {
particle.destroy();
}
}
}
// Destroy explosion container when all particles are gone
if (self.children.length === 0) {
self.destroy();
}
};
return self;
});
var Firework = Container.expand(function () {
var self = Container.call(this);
var colors = ['firework', 'fireworkBlue', 'fireworkGreen', 'fireworkYellow', 'fireworkPurple'];
var colorTints = [0xFFD700, 0x00BFFF, 0x00FF00, 0xFFFF00, 0xDA70D6];
var randomIndex = Math.floor(Math.random() * colors.length);
var randomColor = colors[randomIndex];
self.explosionColor = colorTints[randomIndex];
var fireworkGraphics = self.attachAsset(randomColor, {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.collected = false;
self.lastX = 0;
self.update = function () {
if (!self.collected) {
self.x += self.speed;
self.lastX = self.x;
}
};
self.down = function (x, y, obj) {
if (!self.collected) {
self.collected = true;
LK.getSound('tap').play();
// Create explosion effect with firework's color
var explosion = new Explosion();
explosion.init(self.x, self.y, self.explosionColor);
self.parent.addChild(explosion);
tween(self, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0F0F1E
});
/****
* Game Code
****/
// Game variables
var score = 0;
var missCount = 0;
var fireworks = [];
var gameActive = true;
var beatTiming = 0;
// Rhythm settings - 120 BPM = 2 beats per second = 30 ticks per beat at 60 FPS
var bpm = 120;
var ticksPerBeat = Math.round(3600 / bpm); // 3600 ticks per minute at 60 FPS
var beatCounter = 0;
var nextBeatTick = 0;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var missTxt = new Text2('Misses: 0/3', {
size: 100,
fill: 0xFF6B9D
});
missTxt.anchor.set(0.5, 0);
missTxt.y = 140;
LK.gui.top.addChild(missTxt);
// Update score display
function updateScore() {
scoreTxt.setText('Score: ' + score);
}
// Update miss display
function updateMisses() {
missTxt.setText('Misses: ' + missCount + '/3');
if (missCount >= 3) {
gameActive = false;
LK.showGameOver();
}
}
// Game update loop
game.update = function () {
if (!gameActive) return;
beatTiming++;
// Spawn fireworks on rhythm beats
if (LK.ticks >= nextBeatTick) {
var newFirework = new Firework();
newFirework.x = -100;
newFirework.y = Math.random() * (2732 - 240) + 120;
newFirework.lastX = newFirework.x;
fireworks.push(newFirework);
game.addChild(newFirework);
beatCounter++;
// Move to next beat
nextBeatTick = LK.ticks + ticksPerBeat;
// Gradually increase difficulty by reducing ticksPerBeat (faster spawns)
if (ticksPerBeat > 10) {
ticksPerBeat -= 0.15;
nextBeatTick = LK.ticks + ticksPerBeat;
}
}
// Update fireworks and check for missed ones
for (var a = fireworks.length - 1; a >= 0; a--) {
var firework = fireworks[a];
if (firework.lastX === undefined) {
firework.lastX = firework.x;
}
// Check if firework went off-screen (missed) - only count if not already collected
if (firework.x > 2048 && !firework.collected) {
missCount++;
updateMisses();
firework.destroy();
fireworks.splice(a, 1);
continue;
}
// Clean up collected fireworks
if (firework.collected && firework.alpha === 0) {
score++;
updateScore();
firework.destroy();
fireworks.splice(a, 1);
continue;
}
firework.lastX = firework.x;
}
};
// Handle tap on fireworks
game.down = function (x, y, obj) {
// Event is handled by individual firework classes via their down methods
};
// Start the game music
LK.playMusic('rhythmBeat', {
loop: true
});
// High score tracking
var highScore = storage.highScore || 0;
// Store high score when game ends
LK.on('showGameOver', function () {
if (score > highScore) {
storage.highScore = score;
}
}); ===================================================================
--- original.js
+++ change.js
@@ -171,10 +171,10 @@
var firework = fireworks[a];
if (firework.lastX === undefined) {
firework.lastX = firework.x;
}
- // Check if firework went off-screen (missed)
- if (firework.lastX <= 2048 && firework.x > 2048 && !firework.collected) {
+ // Check if firework went off-screen (missed) - only count if not already collected
+ if (firework.x > 2048 && !firework.collected) {
missCount++;
updateMisses();
firework.destroy();
fireworks.splice(a, 1);