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 Firework = Container.expand(function () {
var self = Container.call(this);
var colors = ['firework', 'fireworkBlue', 'fireworkGreen', 'fireworkYellow', 'fireworkPurple'];
var randomColor = colors[Math.floor(Math.random() * colors.length)];
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();
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 spawnRate = 120;
var spawnCounter = 0;
var gameActive = true;
var beatTiming = 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;
spawnCounter++;
beatTiming++;
// Spawn fireworks based on spawn rate
if (spawnCounter >= spawnRate) {
var newFirework = new Firework();
newFirework.x = -100;
newFirework.y = Math.random() * (2732 - 240) + 120;
newFirework.lastX = newFirework.x;
fireworks.push(newFirework);
game.addChild(newFirework);
spawnCounter = 0;
// Gradually increase difficulty by reducing spawn rate
if (spawnRate > 40) {
spawnRate -= 0.05;
}
}
// 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)
if (firework.lastX <= 2048 && 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
@@ -1,6 +1,150 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Firework = Container.expand(function () {
+ var self = Container.call(this);
+ var colors = ['firework', 'fireworkBlue', 'fireworkGreen', 'fireworkYellow', 'fireworkPurple'];
+ var randomColor = colors[Math.floor(Math.random() * colors.length)];
+ 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();
+ 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: 0x000000
+ backgroundColor: 0x0F0F1E
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var score = 0;
+var missCount = 0;
+var fireworks = [];
+var spawnRate = 120;
+var spawnCounter = 0;
+var gameActive = true;
+var beatTiming = 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;
+ spawnCounter++;
+ beatTiming++;
+ // Spawn fireworks based on spawn rate
+ if (spawnCounter >= spawnRate) {
+ var newFirework = new Firework();
+ newFirework.x = -100;
+ newFirework.y = Math.random() * (2732 - 240) + 120;
+ newFirework.lastX = newFirework.x;
+ fireworks.push(newFirework);
+ game.addChild(newFirework);
+ spawnCounter = 0;
+ // Gradually increase difficulty by reducing spawn rate
+ if (spawnRate > 40) {
+ spawnRate -= 0.05;
+ }
+ }
+ // 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)
+ if (firework.lastX <= 2048 && 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;
+ }
});
\ No newline at end of file