User prompt
make loop until messed up
User prompt
loop music
User prompt
make it match the upbeat music ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
fix music
User prompt
Add music and different songs
Code edit (1 edits merged)
Please save this source code
User prompt
Piano Tiles Symphony
Initial prompt
Make a game about a puano
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var PerfectEffect = Container.expand(function (x, y) { var self = Container.call(this); var effectGraphics = self.attachAsset('perfectEffect', { anchorX: 0.5, anchorY: 0.5 }); self.x = x; self.y = y; self.alpha = 1; self.scale.set(0.5, 0.5); tween(self, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); var index = perfectEffects.indexOf(self); if (index > -1) { perfectEffects.splice(index, 1); } } }); return self; }); var PianoKey = Container.expand(function (lane) { var self = Container.call(this); var keyGraphics = self.attachAsset('pianoKey', { anchorX: 0.5, anchorY: 0.5 }); self.lane = lane; self.pressed = false; self.pressTimer = 0; self.update = function () { if (self.pressed) { self.pressTimer--; if (self.pressTimer <= 0) { self.setUnpressed(); } } }; self.setPressed = function () { if (!self.pressed) { self.pressed = true; self.pressTimer = 10; keyGraphics.removeChild(keyGraphics.children[0]); var pressedGraphics = keyGraphics.attachAsset('pianoKeyPressed', { anchorX: 0.5, anchorY: 0.5 }); } }; self.setUnpressed = function () { if (self.pressed) { self.pressed = false; keyGraphics.removeChild(keyGraphics.children[0]); var normalGraphics = keyGraphics.attachAsset('pianoKey', { anchorX: 0.5, anchorY: 0.5 }); } }; self.down = function (x, y, obj) { handleKeyPress(self.lane); }; return self; }); var PianoTile = Container.expand(function (lane, noteIndex) { var self = Container.call(this); var tileGraphics = self.attachAsset('pianoTile', { anchorX: 0.5, anchorY: 0.5 }); self.lane = lane; self.noteIndex = noteIndex; self.speed = gameSpeed; self.tapped = false; self.lastY = self.y; self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var gameSpeed = 8; var speedIncrement = 0.5; var maxSpeed = 20; var combo = 0; var gameRunning = true; var spawnRate = 90; var spawnCounter = 0; var lanes = 4; var laneWidth = 400; var keyboardY = 2400; var hitZoneY = 2300; var hitZoneHeight = 200; var tiles = []; var pianoKeys = []; var perfectEffects = []; var notes = ['note1', 'note2', 'note3', 'note4']; // Create piano keyboard for (var i = 0; i < lanes; i++) { var key = new PianoKey(i); key.x = i * laneWidth + laneWidth / 2 + 224; key.y = keyboardY; pianoKeys.push(key); game.addChild(key); } // Create score display var scoreText = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Create combo display var comboText = new Text2('', { size: 60, fill: 0xFFD700 }); comboText.anchor.set(0.5, 0); comboText.y = 100; LK.gui.top.addChild(comboText); function updateScore() { scoreText.setText('Score: ' + LK.getScore()); if (combo > 5) { comboText.setText('Combo: ' + combo); } else { comboText.setText(''); } } function spawnTile() { if (!gameRunning) return; var lane = Math.floor(Math.random() * lanes); var tile = new PianoTile(lane, notes[lane]); tile.x = lane * laneWidth + laneWidth / 2 + 224; tile.y = -50; tile.lastY = tile.y; tiles.push(tile); game.addChild(tile); } function handleKeyPress(lane) { if (!gameRunning) return; var hitTile = null; var bestDistance = Infinity; // Find the closest tile in the hit zone for this lane for (var i = 0; i < tiles.length; i++) { var tile = tiles[i]; if (tile.lane === lane && !tile.tapped) { var distance = Math.abs(tile.y - hitZoneY); if (distance < hitZoneHeight && distance < bestDistance) { hitTile = tile; bestDistance = distance; } } } if (hitTile) { hitTile.tapped = true; pianoKeys[lane].setPressed(); // Play note LK.getSound(notes[lane]).play(); // Calculate score based on timing var timingScore = Math.max(1, Math.floor((hitZoneHeight - bestDistance) / hitZoneHeight * 100)); LK.setScore(LK.getScore() + timingScore + combo * 2); combo++; // Perfect hit effect if (bestDistance < 30) { LK.getSound('perfect').play(); var effect = new PerfectEffect(hitTile.x, hitTile.y); perfectEffects.push(effect); game.addChild(effect); } // Increase speed gradually if (gameSpeed < maxSpeed) { gameSpeed += speedIncrement / 100; } updateScore(); // Flash tile before removing tween(hitTile, { alpha: 0 }, { duration: 200, onFinish: function onFinish() { hitTile.destroy(); var index = tiles.indexOf(hitTile); if (index > -1) { tiles.splice(index, 1); } } }); } } game.update = function () { if (!gameRunning) return; // Spawn tiles spawnCounter++; if (spawnCounter >= spawnRate) { spawnTile(); spawnCounter = 0; // Gradually increase spawn rate if (spawnRate > 30) { spawnRate = Math.max(30, spawnRate - 0.2); } } // Update tiles and check for misses for (var i = tiles.length - 1; i >= 0; i--) { var tile = tiles[i]; // Check if tile passed the hit zone without being tapped if (!tile.tapped && tile.lastY < hitZoneY + hitZoneHeight && tile.y >= hitZoneY + hitZoneHeight) { // Missed tile - game over LK.getSound('miss').play(); LK.effects.flashScreen(0xff0000, 1000); gameRunning = false; LK.setTimeout(function () { LK.showGameOver(); }, 1000); return; } // Remove tiles that are off screen if (tile.y > 2800) { tile.destroy(); tiles.splice(i, 1); continue; } tile.lastY = tile.y; } // Check for winning condition (high score achievement) if (LK.getScore() >= 5000) { gameRunning = false; LK.setTimeout(function () { LK.showYouWin(); }, 500); } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,255 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var PerfectEffect = Container.expand(function (x, y) {
+ var self = Container.call(this);
+ var effectGraphics = self.attachAsset('perfectEffect', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = x;
+ self.y = y;
+ self.alpha = 1;
+ self.scale.set(0.5, 0.5);
+ tween(self, {
+ alpha: 0,
+ scaleX: 2,
+ scaleY: 2
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.destroy();
+ var index = perfectEffects.indexOf(self);
+ if (index > -1) {
+ perfectEffects.splice(index, 1);
+ }
+ }
+ });
+ return self;
+});
+var PianoKey = Container.expand(function (lane) {
+ var self = Container.call(this);
+ var keyGraphics = self.attachAsset('pianoKey', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lane = lane;
+ self.pressed = false;
+ self.pressTimer = 0;
+ self.update = function () {
+ if (self.pressed) {
+ self.pressTimer--;
+ if (self.pressTimer <= 0) {
+ self.setUnpressed();
+ }
+ }
+ };
+ self.setPressed = function () {
+ if (!self.pressed) {
+ self.pressed = true;
+ self.pressTimer = 10;
+ keyGraphics.removeChild(keyGraphics.children[0]);
+ var pressedGraphics = keyGraphics.attachAsset('pianoKeyPressed', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ };
+ self.setUnpressed = function () {
+ if (self.pressed) {
+ self.pressed = false;
+ keyGraphics.removeChild(keyGraphics.children[0]);
+ var normalGraphics = keyGraphics.attachAsset('pianoKey', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ };
+ self.down = function (x, y, obj) {
+ handleKeyPress(self.lane);
+ };
+ return self;
+});
+var PianoTile = Container.expand(function (lane, noteIndex) {
+ var self = Container.call(this);
+ var tileGraphics = self.attachAsset('pianoTile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lane = lane;
+ self.noteIndex = noteIndex;
+ self.speed = gameSpeed;
+ self.tapped = false;
+ self.lastY = self.y;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+var gameSpeed = 8;
+var speedIncrement = 0.5;
+var maxSpeed = 20;
+var combo = 0;
+var gameRunning = true;
+var spawnRate = 90;
+var spawnCounter = 0;
+var lanes = 4;
+var laneWidth = 400;
+var keyboardY = 2400;
+var hitZoneY = 2300;
+var hitZoneHeight = 200;
+var tiles = [];
+var pianoKeys = [];
+var perfectEffects = [];
+var notes = ['note1', 'note2', 'note3', 'note4'];
+// Create piano keyboard
+for (var i = 0; i < lanes; i++) {
+ var key = new PianoKey(i);
+ key.x = i * laneWidth + laneWidth / 2 + 224;
+ key.y = keyboardY;
+ pianoKeys.push(key);
+ game.addChild(key);
+}
+// Create score display
+var scoreText = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+// Create combo display
+var comboText = new Text2('', {
+ size: 60,
+ fill: 0xFFD700
+});
+comboText.anchor.set(0.5, 0);
+comboText.y = 100;
+LK.gui.top.addChild(comboText);
+function updateScore() {
+ scoreText.setText('Score: ' + LK.getScore());
+ if (combo > 5) {
+ comboText.setText('Combo: ' + combo);
+ } else {
+ comboText.setText('');
+ }
+}
+function spawnTile() {
+ if (!gameRunning) return;
+ var lane = Math.floor(Math.random() * lanes);
+ var tile = new PianoTile(lane, notes[lane]);
+ tile.x = lane * laneWidth + laneWidth / 2 + 224;
+ tile.y = -50;
+ tile.lastY = tile.y;
+ tiles.push(tile);
+ game.addChild(tile);
+}
+function handleKeyPress(lane) {
+ if (!gameRunning) return;
+ var hitTile = null;
+ var bestDistance = Infinity;
+ // Find the closest tile in the hit zone for this lane
+ for (var i = 0; i < tiles.length; i++) {
+ var tile = tiles[i];
+ if (tile.lane === lane && !tile.tapped) {
+ var distance = Math.abs(tile.y - hitZoneY);
+ if (distance < hitZoneHeight && distance < bestDistance) {
+ hitTile = tile;
+ bestDistance = distance;
+ }
+ }
+ }
+ if (hitTile) {
+ hitTile.tapped = true;
+ pianoKeys[lane].setPressed();
+ // Play note
+ LK.getSound(notes[lane]).play();
+ // Calculate score based on timing
+ var timingScore = Math.max(1, Math.floor((hitZoneHeight - bestDistance) / hitZoneHeight * 100));
+ LK.setScore(LK.getScore() + timingScore + combo * 2);
+ combo++;
+ // Perfect hit effect
+ if (bestDistance < 30) {
+ LK.getSound('perfect').play();
+ var effect = new PerfectEffect(hitTile.x, hitTile.y);
+ perfectEffects.push(effect);
+ game.addChild(effect);
+ }
+ // Increase speed gradually
+ if (gameSpeed < maxSpeed) {
+ gameSpeed += speedIncrement / 100;
+ }
+ updateScore();
+ // Flash tile before removing
+ tween(hitTile, {
+ alpha: 0
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ hitTile.destroy();
+ var index = tiles.indexOf(hitTile);
+ if (index > -1) {
+ tiles.splice(index, 1);
+ }
+ }
+ });
+ }
+}
+game.update = function () {
+ if (!gameRunning) return;
+ // Spawn tiles
+ spawnCounter++;
+ if (spawnCounter >= spawnRate) {
+ spawnTile();
+ spawnCounter = 0;
+ // Gradually increase spawn rate
+ if (spawnRate > 30) {
+ spawnRate = Math.max(30, spawnRate - 0.2);
+ }
+ }
+ // Update tiles and check for misses
+ for (var i = tiles.length - 1; i >= 0; i--) {
+ var tile = tiles[i];
+ // Check if tile passed the hit zone without being tapped
+ if (!tile.tapped && tile.lastY < hitZoneY + hitZoneHeight && tile.y >= hitZoneY + hitZoneHeight) {
+ // Missed tile - game over
+ LK.getSound('miss').play();
+ LK.effects.flashScreen(0xff0000, 1000);
+ gameRunning = false;
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+ return;
+ }
+ // Remove tiles that are off screen
+ if (tile.y > 2800) {
+ tile.destroy();
+ tiles.splice(i, 1);
+ continue;
+ }
+ tile.lastY = tile.y;
+ }
+ // Check for winning condition (high score achievement)
+ if (LK.getScore() >= 5000) {
+ gameRunning = false;
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 500);
+ }
+};
\ No newline at end of file