User prompt
Increase the speed of all notes. Increase the space between horizontal lines. Make the buttons bigger.
Code edit (1 edits merged)
Please save this source code
User prompt
Rhythm Rush
Initial prompt
Let's say there are 2 white lines dividing the screen into three equal parts. At the bottom of the screen there are big green round buttons. Let the notes come down from the top of the screen. There are 3 different types of notes. Green ones are slow, yellow ones are medium speed, and red ones are fast. There is a thin white line just above the buttons.The buttons cannot be pressed unless the notes are below this line. There should be a thin white horizontal line at the very bottom of the screen. If the notes only hit this line, it's considered missed. Missed means user didn't get any points. If the buttons are pressed while the notes are below the white line but above the buttons, half points are taken. If the notes are pressed while they are on the buttons, full points are received. A maximum of 4 notes can appear on the screen at the same time.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Button = Container.expand(function (lane) {
var self = Container.call(this);
self.lane = lane;
self.isPressed = false;
self.buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Position at bottom of lane
self.x = lane * (2048 / 3) + 2048 / 6;
self.y = 2732 - 150;
self.down = function (x, y, obj) {
self.press();
};
self.press = function () {
if (self.isPressed) return;
self.isPressed = true;
self.buttonGraphics.alpha = 0.7;
// Check for notes in this lane
var hitNote = null;
var bestDistance = Infinity;
for (var i = 0; i < notes.length; i++) {
var note = notes[i];
if (note.lane === self.lane && !note.hasBeenHit && note.y >= timingLineY) {
var distance = Math.abs(note.y - self.y);
if (distance < bestDistance) {
bestDistance = distance;
hitNote = note;
}
}
}
if (hitNote) {
hitNote.hasBeenHit = true;
// Calculate points based on timing
var points = 0;
if (bestDistance <= 100) {
// Perfect hit
points = 100;
} else if (bestDistance <= 200) {
// Good hit
points = 50;
}
if (points > 0) {
LK.setScore(LK.getScore() + points);
scoreTxt.setText(LK.getScore());
LK.getSound('hit').play();
// Visual feedback
LK.effects.flashObject(hitNote, 0xffffff, 200);
}
}
// Reset button after short delay
LK.setTimeout(function () {
self.isPressed = false;
self.buttonGraphics.alpha = 1.0;
}, 100);
};
return self;
});
var Note = Container.expand(function (lane, type) {
var self = Container.call(this);
self.lane = lane;
self.type = type;
self.hasBeenHit = false;
// Set speed and asset based on type
if (type === 'slow') {
self.speed = 3;
self.noteGraphics = self.attachAsset('slowNote', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (type === 'medium') {
self.speed = 5;
self.noteGraphics = self.attachAsset('mediumNote', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (type === 'fast') {
self.speed = 7;
self.noteGraphics = self.attachAsset('fastNote', {
anchorX: 0.5,
anchorY: 0.5
});
}
// Position in lane
self.x = lane * (2048 / 3) + 2048 / 6;
self.y = 0;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game variables
var notes = [];
var buttons = [];
var maxNotes = 4;
var spawnTimer = 0;
var spawnInterval = 120; // frames between spawns
var timingLineY = 2732 - 350;
var bottomLineY = 2732 - 50;
// Create lane separators
var lane1 = game.addChild(LK.getAsset('lane', {
anchorX: 0.5,
anchorY: 0
}));
lane1.x = 2048 / 3;
lane1.y = 0;
var lane2 = game.addChild(LK.getAsset('lane', {
anchorX: 0.5,
anchorY: 0
}));
lane2.x = 2048 / 3 * 2;
lane2.y = 0;
// Create timing line
var timingLine = game.addChild(LK.getAsset('timingLine', {
anchorX: 0,
anchorY: 0.5
}));
timingLine.x = 0;
timingLine.y = timingLineY;
// Create bottom line
var bottomLine = game.addChild(LK.getAsset('bottomLine', {
anchorX: 0,
anchorY: 0.5
}));
bottomLine.x = 0;
bottomLine.y = bottomLineY;
// Create buttons
for (var i = 0; i < 3; i++) {
var button = new Button(i);
buttons.push(button);
game.addChild(button);
}
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100;
// Spawn note function
function spawnNote() {
if (notes.length >= maxNotes) return;
var lane = Math.floor(Math.random() * 3);
var noteTypes = ['slow', 'medium', 'fast'];
var type = noteTypes[Math.floor(Math.random() * noteTypes.length)];
var note = new Note(lane, type);
notes.push(note);
game.addChild(note);
}
game.update = function () {
// Spawn notes
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnNote();
spawnTimer = 0;
// Gradually increase spawn rate
if (spawnInterval > 60) {
spawnInterval = Math.max(60, spawnInterval - 1);
}
}
// Update and check notes
for (var i = notes.length - 1; i >= 0; i--) {
var note = notes[i];
// Check if note reached bottom line (missed)
if (note.y >= bottomLineY && !note.hasBeenHit) {
LK.getSound('miss').play();
note.destroy();
notes.splice(i, 1);
continue;
}
// Remove notes that went off screen or were hit
if (note.y > 2732 + 100 || note.hasBeenHit) {
if (note.hasBeenHit) {
// Small delay before removing hit notes for visual feedback
LK.setTimeout(function (noteToRemove, index) {
return function () {
if (noteToRemove && noteToRemove.parent) {
noteToRemove.destroy();
}
var noteIndex = notes.indexOf(noteToRemove);
if (noteIndex !== -1) {
notes.splice(noteIndex, 1);
}
};
}(note, i), 200);
} else {
note.destroy();
notes.splice(i, 1);
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,212 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Button = Container.expand(function (lane) {
+ var self = Container.call(this);
+ self.lane = lane;
+ self.isPressed = false;
+ self.buttonGraphics = self.attachAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Position at bottom of lane
+ self.x = lane * (2048 / 3) + 2048 / 6;
+ self.y = 2732 - 150;
+ self.down = function (x, y, obj) {
+ self.press();
+ };
+ self.press = function () {
+ if (self.isPressed) return;
+ self.isPressed = true;
+ self.buttonGraphics.alpha = 0.7;
+ // Check for notes in this lane
+ var hitNote = null;
+ var bestDistance = Infinity;
+ for (var i = 0; i < notes.length; i++) {
+ var note = notes[i];
+ if (note.lane === self.lane && !note.hasBeenHit && note.y >= timingLineY) {
+ var distance = Math.abs(note.y - self.y);
+ if (distance < bestDistance) {
+ bestDistance = distance;
+ hitNote = note;
+ }
+ }
+ }
+ if (hitNote) {
+ hitNote.hasBeenHit = true;
+ // Calculate points based on timing
+ var points = 0;
+ if (bestDistance <= 100) {
+ // Perfect hit
+ points = 100;
+ } else if (bestDistance <= 200) {
+ // Good hit
+ points = 50;
+ }
+ if (points > 0) {
+ LK.setScore(LK.getScore() + points);
+ scoreTxt.setText(LK.getScore());
+ LK.getSound('hit').play();
+ // Visual feedback
+ LK.effects.flashObject(hitNote, 0xffffff, 200);
+ }
+ }
+ // Reset button after short delay
+ LK.setTimeout(function () {
+ self.isPressed = false;
+ self.buttonGraphics.alpha = 1.0;
+ }, 100);
+ };
+ return self;
+});
+var Note = Container.expand(function (lane, type) {
+ var self = Container.call(this);
+ self.lane = lane;
+ self.type = type;
+ self.hasBeenHit = false;
+ // Set speed and asset based on type
+ if (type === 'slow') {
+ self.speed = 3;
+ self.noteGraphics = self.attachAsset('slowNote', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else if (type === 'medium') {
+ self.speed = 5;
+ self.noteGraphics = self.attachAsset('mediumNote', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else if (type === 'fast') {
+ self.speed = 7;
+ self.noteGraphics = self.attachAsset('fastNote', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ // Position in lane
+ self.x = lane * (2048 / 3) + 2048 / 6;
+ self.y = 0;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
-});
\ No newline at end of file
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var notes = [];
+var buttons = [];
+var maxNotes = 4;
+var spawnTimer = 0;
+var spawnInterval = 120; // frames between spawns
+var timingLineY = 2732 - 350;
+var bottomLineY = 2732 - 50;
+// Create lane separators
+var lane1 = game.addChild(LK.getAsset('lane', {
+ anchorX: 0.5,
+ anchorY: 0
+}));
+lane1.x = 2048 / 3;
+lane1.y = 0;
+var lane2 = game.addChild(LK.getAsset('lane', {
+ anchorX: 0.5,
+ anchorY: 0
+}));
+lane2.x = 2048 / 3 * 2;
+lane2.y = 0;
+// Create timing line
+var timingLine = game.addChild(LK.getAsset('timingLine', {
+ anchorX: 0,
+ anchorY: 0.5
+}));
+timingLine.x = 0;
+timingLine.y = timingLineY;
+// Create bottom line
+var bottomLine = game.addChild(LK.getAsset('bottomLine', {
+ anchorX: 0,
+ anchorY: 0.5
+}));
+bottomLine.x = 0;
+bottomLine.y = bottomLineY;
+// Create buttons
+for (var i = 0; i < 3; i++) {
+ var button = new Button(i);
+ buttons.push(button);
+ game.addChild(button);
+}
+// Create score display
+var scoreTxt = new Text2('0', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 100;
+// Spawn note function
+function spawnNote() {
+ if (notes.length >= maxNotes) return;
+ var lane = Math.floor(Math.random() * 3);
+ var noteTypes = ['slow', 'medium', 'fast'];
+ var type = noteTypes[Math.floor(Math.random() * noteTypes.length)];
+ var note = new Note(lane, type);
+ notes.push(note);
+ game.addChild(note);
+}
+game.update = function () {
+ // Spawn notes
+ spawnTimer++;
+ if (spawnTimer >= spawnInterval) {
+ spawnNote();
+ spawnTimer = 0;
+ // Gradually increase spawn rate
+ if (spawnInterval > 60) {
+ spawnInterval = Math.max(60, spawnInterval - 1);
+ }
+ }
+ // Update and check notes
+ for (var i = notes.length - 1; i >= 0; i--) {
+ var note = notes[i];
+ // Check if note reached bottom line (missed)
+ if (note.y >= bottomLineY && !note.hasBeenHit) {
+ LK.getSound('miss').play();
+ note.destroy();
+ notes.splice(i, 1);
+ continue;
+ }
+ // Remove notes that went off screen or were hit
+ if (note.y > 2732 + 100 || note.hasBeenHit) {
+ if (note.hasBeenHit) {
+ // Small delay before removing hit notes for visual feedback
+ LK.setTimeout(function (noteToRemove, index) {
+ return function () {
+ if (noteToRemove && noteToRemove.parent) {
+ noteToRemove.destroy();
+ }
+ var noteIndex = notes.indexOf(noteToRemove);
+ if (noteIndex !== -1) {
+ notes.splice(noteIndex, 1);
+ }
+ };
+ }(note, i), 200);
+ } else {
+ note.destroy();
+ notes.splice(i, 1);
+ }
+ }
+ }
+};
\ No newline at end of file