/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Lane = Container.expand(function (laneIndex) { var self = Container.call(this); var laneGraphics = self.attachAsset('lane', { anchorX: 0.5, anchorY: 0 }); var hitZone = self.attachAsset('hitZone', { anchorX: 0.5, anchorY: 0.5 }); self.laneIndex = laneIndex; self.x = 2048 / 6 * (laneIndex + 1); hitZone.y = 2500; hitZone.alpha = 0.3; return self; }); var Note = Container.expand(function () { var self = Container.call(this); var noteGraphics = self.attachAsset('note', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.lane = 0; self.isActive = true; self.update = function () { if (self.isActive) { self.y += self.speed; } }; return self; }); var Tower = Container.expand(function () { var self = Container.call(this); var towerGraphics = self.attachAsset('tower', { anchorX: 0.5, anchorY: 0.5 }); self.maxHealth = 100; self.health = self.maxHealth; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { self.health = 0; LK.showGameOver(); } // Flash tower red when damaged LK.effects.flashObject(self, 0xff0000, 300); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ var lanes = []; var notes = []; var tower; var score = 0; var combo = 0; var gameSpeed = 1; var spawnTimer = 0; var healthBarFg; var healthBarBg; var scoreTxt; var comboTxt; var feedbackTxt; var feedbackTimer = 0; // Create lanes for (var i = 0; i < 5; i++) { var lane = new Lane(i); lanes.push(lane); game.addChild(lane); } // Create tower tower = new Tower(); tower.x = 2048 / 2; tower.y = 2600; game.addChild(tower); // Create health bar healthBarBg = LK.getAsset('healthBarBg', { anchorX: 0.5, anchorY: 0 }); healthBarFg = LK.getAsset('healthBar', { anchorX: 0, anchorY: 0 }); LK.gui.top.addChild(healthBarBg); LK.gui.top.addChild(healthBarFg); healthBarBg.x = 0; healthBarBg.y = 100; healthBarFg.x = -150; healthBarFg.y = 100; // Create UI text scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -50; scoreTxt.y = 50; comboTxt = new Text2('Combo: 0', { size: 40, fill: 0xFFFF00 }); comboTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(comboTxt); comboTxt.x = -50; comboTxt.y = 120; feedbackTxt = new Text2('', { size: 80, fill: 0x00FF00 }); feedbackTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(feedbackTxt); function spawnNote() { var note = new Note(); var laneIndex = Math.floor(Math.random() * 5); note.lane = laneIndex; note.x = lanes[laneIndex].x; note.y = -50; note.speed = 3 + gameSpeed * 0.5; notes.push(note); game.addChild(note); } function updateHealthBar() { var healthPercent = tower.health / tower.maxHealth; healthBarFg.scaleX = healthPercent; if (healthPercent > 0.6) { healthBarFg.tint = 0x00ff00; } else if (healthPercent > 0.3) { healthBarFg.tint = 0xffff00; } else { healthBarFg.tint = 0xff0000; } } function checkNoteHit(note, timing) { var distance = Math.abs(note.y - 2500); var perfectRange = 30; var goodRange = 60; if (distance <= perfectRange) { // Perfect hit score += 100 + combo * 10; combo++; showFeedback('PERFECT!', 0x00ff00); LK.getSound('hit').play(); return true; } else if (distance <= goodRange) { // Good hit score += 50 + combo * 5; combo++; showFeedback('GOOD', 0xffff00); LK.getSound('hit').play(); return true; } else { // Miss combo = 0; showFeedback('MISS', 0xff0000); LK.getSound('miss').play(); return false; } } function showFeedback(text, color) { feedbackTxt.setText(text); feedbackTxt.tint = color; feedbackTxt.alpha = 1; feedbackTimer = 60; // Show for 1 second } function updateUI() { scoreTxt.setText('Score: ' + score); comboTxt.setText('Combo: ' + combo); if (feedbackTimer > 0) { feedbackTimer--; feedbackTxt.alpha = feedbackTimer / 60; } } game.down = function (x, y, obj) { // Check which lane was tapped var tappedLane = -1; for (var i = 0; i < lanes.length; i++) { var laneX = lanes[i].x; if (Math.abs(x - laneX) < 100) { tappedLane = i; break; } } if (tappedLane === -1) return; // Find the closest note in that lane var closestNote = null; var closestDistance = Infinity; for (var i = 0; i < notes.length; i++) { var note = notes[i]; if (note.lane === tappedLane && note.isActive) { var distance = Math.abs(note.y - 2500); if (distance < closestDistance && distance < 100) { closestDistance = distance; closestNote = note; } } } if (closestNote) { var hit = checkNoteHit(closestNote, 0); if (hit) { closestNote.isActive = false; closestNote.destroy(); var index = notes.indexOf(closestNote); if (index > -1) { notes.splice(index, 1); } } } }; game.update = function () { // Spawn notes spawnTimer++; var spawnRate = Math.max(30 - Math.floor(LK.ticks / 1800), 15); // Increase spawn rate over time if (spawnTimer >= spawnRate) { spawnNote(); spawnTimer = 0; } // Update notes for (var i = notes.length - 1; i >= 0; i--) { var note = notes[i]; if (!note.isActive) continue; // Check if note reached the bottom without being hit if (note.y > 2550) { tower.takeDamage(10); combo = 0; showFeedback('MISSED!', 0xff0000); LK.getSound('miss').play(); note.destroy(); notes.splice(i, 1); continue; } // Remove notes that are way off screen if (note.y > 2800) { note.destroy(); notes.splice(i, 1); } } // Increase difficulty over time if (LK.ticks % 1800 === 0) { // Every 30 seconds gameSpeed += 0.1; } // Update UI updateUI(); updateHealthBar(); // Update score in LK system LK.setScore(score); }; // Start background music LK.playMusic('bgmusic');
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,270 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Lane = Container.expand(function (laneIndex) {
+ var self = Container.call(this);
+ var laneGraphics = self.attachAsset('lane', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ var hitZone = self.attachAsset('hitZone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.laneIndex = laneIndex;
+ self.x = 2048 / 6 * (laneIndex + 1);
+ hitZone.y = 2500;
+ hitZone.alpha = 0.3;
+ return self;
+});
+var Note = Container.expand(function () {
+ var self = Container.call(this);
+ var noteGraphics = self.attachAsset('note', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.lane = 0;
+ self.isActive = true;
+ self.update = function () {
+ if (self.isActive) {
+ self.y += self.speed;
+ }
+ };
+ return self;
+});
+var Tower = Container.expand(function () {
+ var self = Container.call(this);
+ var towerGraphics = self.attachAsset('tower', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxHealth = 100;
+ self.health = self.maxHealth;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ if (self.health <= 0) {
+ self.health = 0;
+ LK.showGameOver();
+ }
+ // Flash tower red when damaged
+ LK.effects.flashObject(self, 0xff0000, 300);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+var lanes = [];
+var notes = [];
+var tower;
+var score = 0;
+var combo = 0;
+var gameSpeed = 1;
+var spawnTimer = 0;
+var healthBarFg;
+var healthBarBg;
+var scoreTxt;
+var comboTxt;
+var feedbackTxt;
+var feedbackTimer = 0;
+// Create lanes
+for (var i = 0; i < 5; i++) {
+ var lane = new Lane(i);
+ lanes.push(lane);
+ game.addChild(lane);
+}
+// Create tower
+tower = new Tower();
+tower.x = 2048 / 2;
+tower.y = 2600;
+game.addChild(tower);
+// Create health bar
+healthBarBg = LK.getAsset('healthBarBg', {
+ anchorX: 0.5,
+ anchorY: 0
+});
+healthBarFg = LK.getAsset('healthBar', {
+ anchorX: 0,
+ anchorY: 0
+});
+LK.gui.top.addChild(healthBarBg);
+LK.gui.top.addChild(healthBarFg);
+healthBarBg.x = 0;
+healthBarBg.y = 100;
+healthBarFg.x = -150;
+healthBarFg.y = 100;
+// Create UI text
+scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.topRight.addChild(scoreTxt);
+scoreTxt.x = -50;
+scoreTxt.y = 50;
+comboTxt = new Text2('Combo: 0', {
+ size: 40,
+ fill: 0xFFFF00
+});
+comboTxt.anchor.set(0.5, 0);
+LK.gui.topRight.addChild(comboTxt);
+comboTxt.x = -50;
+comboTxt.y = 120;
+feedbackTxt = new Text2('', {
+ size: 80,
+ fill: 0x00FF00
+});
+feedbackTxt.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(feedbackTxt);
+function spawnNote() {
+ var note = new Note();
+ var laneIndex = Math.floor(Math.random() * 5);
+ note.lane = laneIndex;
+ note.x = lanes[laneIndex].x;
+ note.y = -50;
+ note.speed = 3 + gameSpeed * 0.5;
+ notes.push(note);
+ game.addChild(note);
+}
+function updateHealthBar() {
+ var healthPercent = tower.health / tower.maxHealth;
+ healthBarFg.scaleX = healthPercent;
+ if (healthPercent > 0.6) {
+ healthBarFg.tint = 0x00ff00;
+ } else if (healthPercent > 0.3) {
+ healthBarFg.tint = 0xffff00;
+ } else {
+ healthBarFg.tint = 0xff0000;
+ }
+}
+function checkNoteHit(note, timing) {
+ var distance = Math.abs(note.y - 2500);
+ var perfectRange = 30;
+ var goodRange = 60;
+ if (distance <= perfectRange) {
+ // Perfect hit
+ score += 100 + combo * 10;
+ combo++;
+ showFeedback('PERFECT!', 0x00ff00);
+ LK.getSound('hit').play();
+ return true;
+ } else if (distance <= goodRange) {
+ // Good hit
+ score += 50 + combo * 5;
+ combo++;
+ showFeedback('GOOD', 0xffff00);
+ LK.getSound('hit').play();
+ return true;
+ } else {
+ // Miss
+ combo = 0;
+ showFeedback('MISS', 0xff0000);
+ LK.getSound('miss').play();
+ return false;
+ }
+}
+function showFeedback(text, color) {
+ feedbackTxt.setText(text);
+ feedbackTxt.tint = color;
+ feedbackTxt.alpha = 1;
+ feedbackTimer = 60; // Show for 1 second
+}
+function updateUI() {
+ scoreTxt.setText('Score: ' + score);
+ comboTxt.setText('Combo: ' + combo);
+ if (feedbackTimer > 0) {
+ feedbackTimer--;
+ feedbackTxt.alpha = feedbackTimer / 60;
+ }
+}
+game.down = function (x, y, obj) {
+ // Check which lane was tapped
+ var tappedLane = -1;
+ for (var i = 0; i < lanes.length; i++) {
+ var laneX = lanes[i].x;
+ if (Math.abs(x - laneX) < 100) {
+ tappedLane = i;
+ break;
+ }
+ }
+ if (tappedLane === -1) return;
+ // Find the closest note in that lane
+ var closestNote = null;
+ var closestDistance = Infinity;
+ for (var i = 0; i < notes.length; i++) {
+ var note = notes[i];
+ if (note.lane === tappedLane && note.isActive) {
+ var distance = Math.abs(note.y - 2500);
+ if (distance < closestDistance && distance < 100) {
+ closestDistance = distance;
+ closestNote = note;
+ }
+ }
+ }
+ if (closestNote) {
+ var hit = checkNoteHit(closestNote, 0);
+ if (hit) {
+ closestNote.isActive = false;
+ closestNote.destroy();
+ var index = notes.indexOf(closestNote);
+ if (index > -1) {
+ notes.splice(index, 1);
+ }
+ }
+ }
+};
+game.update = function () {
+ // Spawn notes
+ spawnTimer++;
+ var spawnRate = Math.max(30 - Math.floor(LK.ticks / 1800), 15); // Increase spawn rate over time
+ if (spawnTimer >= spawnRate) {
+ spawnNote();
+ spawnTimer = 0;
+ }
+ // Update notes
+ for (var i = notes.length - 1; i >= 0; i--) {
+ var note = notes[i];
+ if (!note.isActive) continue;
+ // Check if note reached the bottom without being hit
+ if (note.y > 2550) {
+ tower.takeDamage(10);
+ combo = 0;
+ showFeedback('MISSED!', 0xff0000);
+ LK.getSound('miss').play();
+ note.destroy();
+ notes.splice(i, 1);
+ continue;
+ }
+ // Remove notes that are way off screen
+ if (note.y > 2800) {
+ note.destroy();
+ notes.splice(i, 1);
+ }
+ }
+ // Increase difficulty over time
+ if (LK.ticks % 1800 === 0) {
+ // Every 30 seconds
+ gameSpeed += 0.1;
+ }
+ // Update UI
+ updateUI();
+ updateHealthBar();
+ // Update score in LK system
+ LK.setScore(score);
+};
+// Start background music
+LK.playMusic('bgmusic');
\ No newline at end of file