User prompt
Please fix the bug: 'storage.get is not a function' in or related to this line: 'var topScore = storage.get('topScore') || 0;' Line Number: 194 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'storage is not defined' in or related to this line: 'var topScore = storage.get('topScore') || 0;' Line Number: 193
User prompt
show top score
User prompt
randomize the fall
User prompt
no note falls in same position with other note
User prompt
hits zones light up in yellow
User prompt
each hit counts as 20 points
User prompt
all notes fall in different positions
User prompt
first two notes dont fall in the same line
User prompt
amount of notes falling changes
User prompt
fall speed increases by 20% with each 500 points
User prompt
fall speed increases by 10% with each 500 points
User prompt
fewer notes fall at the same time
User prompt
notes fall in lesser amounts
User prompt
notes fall with less frequency
User prompt
notes fall slower
User prompt
notes keep falling forever
User prompt
notes fall until game ends
User prompt
count each miss as one
User prompt
dont count empty clicks as miss
User prompt
show misses as notes
User prompt
count each miss as a total of one point
User prompt
each miss adds one point
User prompt
each miss counts as one
User prompt
show a miss counter bottom right
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Note class var Note = Container.expand(function () { var self = Container.call(this); // lane: 0-3 self.lane = 0; self.hit = false; self.missed = false; self.speed = 12; // Will be set dynamically // Attach note asset (set in .init) self.noteAsset = null; // Feedback effect self.effect = null; // Called every tick self.update = function () { self.y += self.speed; // If note goes past hit zone and not hit, mark as missed if (!self.hit && !self.missed && self.y > hitZoneY + hitZoneHeight) { self.missed = true; showMissEffect(self); } }; // Show hit feedback self.showHit = function () { if (self.effect) return; self.effect = self.attachAsset('hitEffect', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, alpha: 0.7 }); tween(self.effect, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { if (self.effect) { self.effect.destroy(); self.effect = null; } } }); }; // Show miss feedback self.showMiss = function () { if (self.effect) return; self.effect = self.attachAsset('missEffect', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, alpha: 0.7 }); tween(self.effect, { alpha: 0 }, { duration: 400, onFinish: function onFinish() { if (self.effect) { self.effect.destroy(); self.effect = null; } } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181818 }); /**** * Game Code ****/ // Lane setup // Four note lanes (different colors for clarity) // Hit zone highlight // Notes (different colors for each lane) // Feedback shapes // Sound effects // Music (placeholder id) var laneCount = 4; var laneWidth = 400; var laneSpacing = 32; var totalLaneWidth = laneCount * laneWidth + (laneCount - 1) * laneSpacing; var leftMargin = Math.floor((2048 - totalLaneWidth) / 2); // Hit zone setup var hitZoneHeight = 160; // Increased from 80 to 160 for higher volume var hitZoneY = 2732 - 320; // 320px from bottom // Lane X positions var laneXs = []; for (var i = 0; i < laneCount; i++) { laneXs[i] = leftMargin + i * (laneWidth + laneSpacing) + laneWidth / 2; } // Draw lanes var lanes = []; for (var i = 0; i < laneCount; i++) { var laneAssetId = 'lane' + (i + 1); var lane = LK.getAsset(laneAssetId, { anchorX: 0.5, anchorY: 0, x: laneXs[i], y: 0, width: laneWidth, height: 2200 }); game.addChild(lane); lanes.push(lane); } // Draw hit zones var hitZones = []; for (var i = 0; i < laneCount; i++) { var hitZone = LK.getAsset('hitZone', { anchorX: 0.5, anchorY: 0, x: laneXs[i], y: hitZoneY, width: laneWidth, height: hitZoneHeight, alpha: 0.12 }); game.addChild(hitZone); hitZones.push(hitZone); } // Score and combo display var score = 0; var combo = 0; var maxCombo = 0; var scoreTxt = new Text2('Score: 0', { size: 90, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var comboTxt = new Text2('', { size: 70, fill: 0xFFFF00 }); comboTxt.anchor.set(0.5, 0); LK.gui.top.addChild(comboTxt); comboTxt.y = 110; // Miss counter display (bottom right) var missTxt = new Text2('', { size: 80, fill: 0xFF4444 }); missTxt.anchor.set(1, 1); // bottom right LK.gui.bottomRight.addChild(missTxt); missTxt.x = 0; missTxt.y = 0; // Notes array var notes = []; // Song data: array of {time, lane} // For MVP, a simple hardcoded pattern (in ms, relative to song start) var songNotes = [{ time: 800, lane: 0 }, { time: 1800, lane: 1 }, { time: 2800, lane: 2 }, { time: 3800, lane: 3 }, { time: 4800, lane: 0 }, { time: 5800, lane: 1 }, { time: 6800, lane: 2 }, { time: 7800, lane: 3 }]; // Song parameters var songDuration = 9000; // ms var noteSpeed = 7; // px per frame (will increase) var noteTravelTime = 1200; // ms from spawn to hit zone // Timing var songStartTime = null; var lastTickTime = null; var songPlaying = false; var nextNoteIndex = 0; // Miss counter var misses = 0; var maxMisses = 5; // Feedback effect for misses function showMissEffect(note) { note.showMiss(); combo = 0; updateCombo(); LK.getSound('noteMiss').play(); // Flash lane LK.effects.flashObject(lanes[note.lane], 0xff0000, 200); // Increment miss counter and check for game over misses++; missTxt.setText('Misses: ' + misses + ' / ' + maxMisses); if (misses >= maxMisses) { failSong(); } } // Feedback effect for hits function showHitEffect(note) { note.showHit(); LK.getSound('noteHit').play(); // Flash lane LK.effects.flashObject(lanes[note.lane], 0x00ff00, 120); } // Update score and combo display function updateScore() { scoreTxt.setText('Score: ' + score); } function updateCombo() { if (combo > 1) { comboTxt.setText('Combo: ' + combo); } else { comboTxt.setText(''); } } // Start song and reset state function startSong() { score = 0; combo = 0; maxCombo = 0; misses = 0; missTxt.setText('Misses: 0 / ' + maxMisses); updateScore(); updateCombo(); songStartTime = Date.now(); lastTickTime = songStartTime; songPlaying = true; nextNoteIndex = 0; // Remove old notes for (var i = notes.length - 1; i >= 0; i--) { notes[i].destroy(); notes.splice(i, 1); } // Play music LK.playMusic('song1'); } // End song (win) function endSong() { songPlaying = false; LK.showYouWin(); } // End song (fail) function failSong() { songPlaying = false; LK.showGameOver(); } // Spawn a note function spawnNote(lane, spawnTime) { var note = new Note(); note.lane = lane; note.speed = noteSpeed; var noteAssetId = 'note' + (lane + 1); note.noteAsset = note.attachAsset(noteAssetId, { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); // X position: center of lane note.x = laneXs[lane]; // Y position: spawn above screen so it reaches hit zone at correct time note.y = getNoteSpawnY(); notes.push(note); game.addChild(note); note.spawnTime = spawnTime; // Track lastWasIntersecting for hit zone lighting note.lastWasIntersecting = false; return note; } // Calculate note spawn Y so it reaches hit zone at the right time function getNoteSpawnY() { // Distance = speed * frames // frames = noteTravelTime / (1000/60) var frames = noteTravelTime / (1000 / 60); var distance = frames * noteSpeed; // Start notes at the very top of the screen (y = 0 - note height/2) return 0 - 40; // 40 is half the note height (80) } // Find the closest note in a lane to the hit zone (not yet hit or missed) function getHittableNote(lane) { var best = null; var bestDist = 99999; for (var i = 0; i < notes.length; i++) { var note = notes[i]; if (note.lane !== lane) continue; if (note.hit || note.missed) continue; var dist = Math.abs(note.y - (hitZoneY + hitZoneHeight / 2)); if (dist < bestDist) { best = note; bestDist = dist; } } return best; } // Handle tap input function handleTap(x, y, obj) { // Only if song is playing if (!songPlaying) return; // Which lane? for (var i = 0; i < laneCount; i++) { var laneLeft = laneXs[i] - laneWidth / 2; var laneRight = laneXs[i] + laneWidth / 2; if (x >= laneLeft && x <= laneRight) { // Check for hittable note in this lane var note = getHittableNote(i); if (note) { var noteCenterY = note.y; var hitCenterY = hitZoneY + hitZoneHeight / 2; var hitWindow = hitZoneHeight / 2; // Match hit window to half the new hit zone height if (Math.abs(noteCenterY - hitCenterY) <= hitWindow) { // Hit! note.hit = true; showHitEffect(note); score += 100 + combo * 10; combo += 1; if (combo > maxCombo) maxCombo = combo; updateScore(); updateCombo(); // Remove note after feedback tween(note, { alpha: 0 }, { duration: 120, onFinish: function onFinish() { note.destroy(); } }); return; } } // Miss (tapped but no note in window) combo = 0; updateCombo(); LK.getSound('noteMiss').play(); LK.effects.flashObject(lanes[i], 0xff0000, 120); return; } } } // Attach tap handler game.down = function (x, y, obj) { handleTap(x, y, obj); }; // No drag or move needed for this game game.move = function (x, y, obj) {}; game.up = function (x, y, obj) {}; // Main update loop game.update = function () { if (!songPlaying) return; var now = Date.now(); var songElapsed = now - songStartTime; // Spawn notes as their time comes while (nextNoteIndex < songNotes.length && songNotes[nextNoteIndex].time <= songElapsed + noteTravelTime) { var noteData = songNotes[nextNoteIndex]; spawnNote(noteData.lane, noteData.time); nextNoteIndex++; } // Update notes for (var i = notes.length - 1; i >= 0; i--) { var note = notes[i]; note.update(); // Light up hitbar when note enters hit zone if (!note.lastWasIntersecting) { // Check intersection with hit zone for this note's lane var hitZone = hitZones[note.lane]; if (note.intersects(hitZone)) { // Animate hit zone alpha up, then back down, and tint yellow var originalTint = hitZone.tint !== undefined ? hitZone.tint : 0xffffff; hitZone.tint = 0xffff00; tween(hitZone, { alpha: 0.45 }, { duration: 60, onFinish: function onFinish() { tween(hitZone, { alpha: 0.12 }, { duration: 180, onFinish: function onFinish() { hitZone.tint = originalTint; } }); } }); } } note.lastWasIntersecting = note.intersects(hitZones[note.lane]); // Remove notes that are off screen or hit/missed and faded out if (note.y > 2732 + 100 || note.hit && note.alpha === 0 || note.missed && note.alpha === 0) { note.destroy(); notes.splice(i, 1); } // If note just missed if (note.missed && !note._missFeedbackShown) { note._missFeedbackShown = true; showMissEffect(note); } } // End song if all notes are done and no notes left // (Removed endSong call so falling continues after song duration) // Increase speed as song progresses (simple difficulty ramp) if (songElapsed > 4000 && noteSpeed < 10) { noteSpeed = 10; } if (songElapsed > 7000 && noteSpeed < 13) { noteSpeed = 13; } }; // Start the game startSong(); // Play music (already started in startSong) LK.playMusic('song1');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Note class
var Note = Container.expand(function () {
var self = Container.call(this);
// lane: 0-3
self.lane = 0;
self.hit = false;
self.missed = false;
self.speed = 12; // Will be set dynamically
// Attach note asset (set in .init)
self.noteAsset = null;
// Feedback effect
self.effect = null;
// Called every tick
self.update = function () {
self.y += self.speed;
// If note goes past hit zone and not hit, mark as missed
if (!self.hit && !self.missed && self.y > hitZoneY + hitZoneHeight) {
self.missed = true;
showMissEffect(self);
}
};
// Show hit feedback
self.showHit = function () {
if (self.effect) return;
self.effect = self.attachAsset('hitEffect', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
alpha: 0.7
});
tween(self.effect, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
if (self.effect) {
self.effect.destroy();
self.effect = null;
}
}
});
};
// Show miss feedback
self.showMiss = function () {
if (self.effect) return;
self.effect = self.attachAsset('missEffect', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
alpha: 0.7
});
tween(self.effect, {
alpha: 0
}, {
duration: 400,
onFinish: function onFinish() {
if (self.effect) {
self.effect.destroy();
self.effect = null;
}
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Lane setup
// Four note lanes (different colors for clarity)
// Hit zone highlight
// Notes (different colors for each lane)
// Feedback shapes
// Sound effects
// Music (placeholder id)
var laneCount = 4;
var laneWidth = 400;
var laneSpacing = 32;
var totalLaneWidth = laneCount * laneWidth + (laneCount - 1) * laneSpacing;
var leftMargin = Math.floor((2048 - totalLaneWidth) / 2);
// Hit zone setup
var hitZoneHeight = 160; // Increased from 80 to 160 for higher volume
var hitZoneY = 2732 - 320; // 320px from bottom
// Lane X positions
var laneXs = [];
for (var i = 0; i < laneCount; i++) {
laneXs[i] = leftMargin + i * (laneWidth + laneSpacing) + laneWidth / 2;
}
// Draw lanes
var lanes = [];
for (var i = 0; i < laneCount; i++) {
var laneAssetId = 'lane' + (i + 1);
var lane = LK.getAsset(laneAssetId, {
anchorX: 0.5,
anchorY: 0,
x: laneXs[i],
y: 0,
width: laneWidth,
height: 2200
});
game.addChild(lane);
lanes.push(lane);
}
// Draw hit zones
var hitZones = [];
for (var i = 0; i < laneCount; i++) {
var hitZone = LK.getAsset('hitZone', {
anchorX: 0.5,
anchorY: 0,
x: laneXs[i],
y: hitZoneY,
width: laneWidth,
height: hitZoneHeight,
alpha: 0.12
});
game.addChild(hitZone);
hitZones.push(hitZone);
}
// Score and combo display
var score = 0;
var combo = 0;
var maxCombo = 0;
var scoreTxt = new Text2('Score: 0', {
size: 90,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var comboTxt = new Text2('', {
size: 70,
fill: 0xFFFF00
});
comboTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(comboTxt);
comboTxt.y = 110;
// Miss counter display (bottom right)
var missTxt = new Text2('', {
size: 80,
fill: 0xFF4444
});
missTxt.anchor.set(1, 1); // bottom right
LK.gui.bottomRight.addChild(missTxt);
missTxt.x = 0;
missTxt.y = 0;
// Notes array
var notes = [];
// Song data: array of {time, lane}
// For MVP, a simple hardcoded pattern (in ms, relative to song start)
var songNotes = [{
time: 800,
lane: 0
}, {
time: 1800,
lane: 1
}, {
time: 2800,
lane: 2
}, {
time: 3800,
lane: 3
}, {
time: 4800,
lane: 0
}, {
time: 5800,
lane: 1
}, {
time: 6800,
lane: 2
}, {
time: 7800,
lane: 3
}];
// Song parameters
var songDuration = 9000; // ms
var noteSpeed = 7; // px per frame (will increase)
var noteTravelTime = 1200; // ms from spawn to hit zone
// Timing
var songStartTime = null;
var lastTickTime = null;
var songPlaying = false;
var nextNoteIndex = 0;
// Miss counter
var misses = 0;
var maxMisses = 5;
// Feedback effect for misses
function showMissEffect(note) {
note.showMiss();
combo = 0;
updateCombo();
LK.getSound('noteMiss').play();
// Flash lane
LK.effects.flashObject(lanes[note.lane], 0xff0000, 200);
// Increment miss counter and check for game over
misses++;
missTxt.setText('Misses: ' + misses + ' / ' + maxMisses);
if (misses >= maxMisses) {
failSong();
}
}
// Feedback effect for hits
function showHitEffect(note) {
note.showHit();
LK.getSound('noteHit').play();
// Flash lane
LK.effects.flashObject(lanes[note.lane], 0x00ff00, 120);
}
// Update score and combo display
function updateScore() {
scoreTxt.setText('Score: ' + score);
}
function updateCombo() {
if (combo > 1) {
comboTxt.setText('Combo: ' + combo);
} else {
comboTxt.setText('');
}
}
// Start song and reset state
function startSong() {
score = 0;
combo = 0;
maxCombo = 0;
misses = 0;
missTxt.setText('Misses: 0 / ' + maxMisses);
updateScore();
updateCombo();
songStartTime = Date.now();
lastTickTime = songStartTime;
songPlaying = true;
nextNoteIndex = 0;
// Remove old notes
for (var i = notes.length - 1; i >= 0; i--) {
notes[i].destroy();
notes.splice(i, 1);
}
// Play music
LK.playMusic('song1');
}
// End song (win)
function endSong() {
songPlaying = false;
LK.showYouWin();
}
// End song (fail)
function failSong() {
songPlaying = false;
LK.showGameOver();
}
// Spawn a note
function spawnNote(lane, spawnTime) {
var note = new Note();
note.lane = lane;
note.speed = noteSpeed;
var noteAssetId = 'note' + (lane + 1);
note.noteAsset = note.attachAsset(noteAssetId, {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
// X position: center of lane
note.x = laneXs[lane];
// Y position: spawn above screen so it reaches hit zone at correct time
note.y = getNoteSpawnY();
notes.push(note);
game.addChild(note);
note.spawnTime = spawnTime;
// Track lastWasIntersecting for hit zone lighting
note.lastWasIntersecting = false;
return note;
}
// Calculate note spawn Y so it reaches hit zone at the right time
function getNoteSpawnY() {
// Distance = speed * frames
// frames = noteTravelTime / (1000/60)
var frames = noteTravelTime / (1000 / 60);
var distance = frames * noteSpeed;
// Start notes at the very top of the screen (y = 0 - note height/2)
return 0 - 40; // 40 is half the note height (80)
}
// Find the closest note in a lane to the hit zone (not yet hit or missed)
function getHittableNote(lane) {
var best = null;
var bestDist = 99999;
for (var i = 0; i < notes.length; i++) {
var note = notes[i];
if (note.lane !== lane) continue;
if (note.hit || note.missed) continue;
var dist = Math.abs(note.y - (hitZoneY + hitZoneHeight / 2));
if (dist < bestDist) {
best = note;
bestDist = dist;
}
}
return best;
}
// Handle tap input
function handleTap(x, y, obj) {
// Only if song is playing
if (!songPlaying) return;
// Which lane?
for (var i = 0; i < laneCount; i++) {
var laneLeft = laneXs[i] - laneWidth / 2;
var laneRight = laneXs[i] + laneWidth / 2;
if (x >= laneLeft && x <= laneRight) {
// Check for hittable note in this lane
var note = getHittableNote(i);
if (note) {
var noteCenterY = note.y;
var hitCenterY = hitZoneY + hitZoneHeight / 2;
var hitWindow = hitZoneHeight / 2; // Match hit window to half the new hit zone height
if (Math.abs(noteCenterY - hitCenterY) <= hitWindow) {
// Hit!
note.hit = true;
showHitEffect(note);
score += 100 + combo * 10;
combo += 1;
if (combo > maxCombo) maxCombo = combo;
updateScore();
updateCombo();
// Remove note after feedback
tween(note, {
alpha: 0
}, {
duration: 120,
onFinish: function onFinish() {
note.destroy();
}
});
return;
}
}
// Miss (tapped but no note in window)
combo = 0;
updateCombo();
LK.getSound('noteMiss').play();
LK.effects.flashObject(lanes[i], 0xff0000, 120);
return;
}
}
}
// Attach tap handler
game.down = function (x, y, obj) {
handleTap(x, y, obj);
};
// No drag or move needed for this game
game.move = function (x, y, obj) {};
game.up = function (x, y, obj) {};
// Main update loop
game.update = function () {
if (!songPlaying) return;
var now = Date.now();
var songElapsed = now - songStartTime;
// Spawn notes as their time comes
while (nextNoteIndex < songNotes.length && songNotes[nextNoteIndex].time <= songElapsed + noteTravelTime) {
var noteData = songNotes[nextNoteIndex];
spawnNote(noteData.lane, noteData.time);
nextNoteIndex++;
}
// Update notes
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
note.update();
// Light up hitbar when note enters hit zone
if (!note.lastWasIntersecting) {
// Check intersection with hit zone for this note's lane
var hitZone = hitZones[note.lane];
if (note.intersects(hitZone)) {
// Animate hit zone alpha up, then back down, and tint yellow
var originalTint = hitZone.tint !== undefined ? hitZone.tint : 0xffffff;
hitZone.tint = 0xffff00;
tween(hitZone, {
alpha: 0.45
}, {
duration: 60,
onFinish: function onFinish() {
tween(hitZone, {
alpha: 0.12
}, {
duration: 180,
onFinish: function onFinish() {
hitZone.tint = originalTint;
}
});
}
});
}
}
note.lastWasIntersecting = note.intersects(hitZones[note.lane]);
// Remove notes that are off screen or hit/missed and faded out
if (note.y > 2732 + 100 || note.hit && note.alpha === 0 || note.missed && note.alpha === 0) {
note.destroy();
notes.splice(i, 1);
}
// If note just missed
if (note.missed && !note._missFeedbackShown) {
note._missFeedbackShown = true;
showMissEffect(note);
}
}
// End song if all notes are done and no notes left
// (Removed endSong call so falling continues after song duration)
// Increase speed as song progresses (simple difficulty ramp)
if (songElapsed > 4000 && noteSpeed < 10) {
noteSpeed = 10;
}
if (songElapsed > 7000 && noteSpeed < 13) {
noteSpeed = 13;
}
};
// Start the game
startSong();
// Play music (already started in startSong)
LK.playMusic('song1');