User prompt
game ends in 5 misses
User prompt
falling continues until game over
User prompt
hit zones light up in yellow
User prompt
make hitzones eclipse
User prompt
light up hitbars when bars get in the hitbars
User prompt
increase volume of hit zones
User prompt
bars have fewer frequency
User prompt
bars start falling from the top
User prompt
bars fall from higher
User prompt
make fall down slower
Code edit (1 edits merged)
Please save this source code
User prompt
Rhythm Tap Hero
Initial prompt
ı want a game like guitar hero
/****
* 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
****/
// Music (placeholder id)
// Sound effects
// Feedback shapes
// Notes (different colors for each lane)
// Hit zone highlight
// Four note lanes (different colors for clarity)
// Lane setup
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;
// 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;
// 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);
}
// 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;
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
if (songElapsed > songDuration && notes.length === 0) {
endSong();
}
// 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'); ===================================================================
--- original.js
+++ change.js
@@ -364,18 +364,23 @@
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
+ // 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
+ duration: 180,
+ onFinish: function onFinish() {
+ hitZone.tint = originalTint;
+ }
});
}
});
}