Code edit (2 edits merged)
Please save this source code
User prompt
Elimina comentarios simples //
User prompt
haz que los ms tardados salgan con -
User prompt
Elimina codigo rebundante
Code edit (1 edits merged)
Please save this source code
User prompt
agrega puntos. marvelous = 350, perfect = 300, good = 100, bad = 50, fail = resta
User prompt
agrega puntos. marvelous = 350, perfect = 300, good = 100, bad = 50, fail = resta
User prompt
Optimiza todo lo que es mostrar el resultado
User prompt
Please fix the bug: 'ReferenceError: failCount is not defined' in or related to this line: 'failCount++;' Line Number: 141
User prompt
Please fix the bug: 'speed is not defined' in or related to this line: 'tween(hitAccuracy, {' Line Number: 41
User prompt
optimiza todo lo que es absMS
User prompt
Optimiza todo showFeedback
User prompt
Optimiza todo el codigo
Code edit (1 edits merged)
Please save this source code
User prompt
agrega dos variables boleanas para ocultar o mostrar el contador de precisión y el de ms
User prompt
Arregla el error que muestra muchos decimales en los ms y elimina el + de los positivos
User prompt
elimina el texto var accuracyText
User prompt
Please fix the bug: 'ReferenceError: failCount is not defined' in or related to this line: 'failCount++;' Line Number: 146
User prompt
Please fix the bug: 'ReferenceError: updateAccuracyDisplay is not defined' in or related to this line: 'updateAccuracyDisplay();' Line Number: 147
Code edit (1 edits merged)
Please save this source code
User prompt
Elimina accurracy text
User prompt
optimiza los textos con una función reusable
Code edit (1 edits merged)
Please save this source code
User prompt
Los textos no son visibles
User prompt
agrega textos en la esquina inferior derecha para visualizar el acurracy
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Note class: creates a note at a random (x, y) position var Note = Container.expand(function () { var self = Container.call(this); var hitZone = self.attachAsset('hit', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.6, scaleY: 1.6 }); hitZone.alpha = 0.4; // Add hitAccuracy ring, starts much further out var hitAccuracy = self.attachAsset('hit', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.5, scaleY: 2.5 }); hitAccuracy.alpha = 0.25; // Animate hitAccuracy ring moving toward hitZone var hitAccuracyTargetScale = 1.6; var hitAccuracyStartScale = 3.4; hitAccuracy.scaleX = hitAccuracyStartScale; hitAccuracy.scaleY = hitAccuracyStartScale; // Use tween plugin for smooth animation, duration is now linearly dependent on speed only tween(hitAccuracy, { scaleX: hitAccuracyTargetScale, scaleY: hitAccuracyTargetScale }, { duration: 1000 / speed }); var noteAsset = self.attachAsset('note', { anchorX: 0.5, anchorY: 0.5 }); var margin = 100; self.x = margin + Math.random() * (2048 - 2 * margin); self.y = margin + Math.random() * (2732 - 2 * margin); // Timing windows in ms (example values, tune as needed) var MARVELOUS_WINDOW = 30; var PERFECT_WINDOW = 70; var GOOD_WINDOW = 120; var BAD_WINDOW = 180; var FAIL_WINDOW = 250; // Store the time when the note is created and when the hit zone is reached self.spawnTime = Date.now(); self.hitZoneTime = self.spawnTime + 1000 / speed; // duration of tween // Helper to show feedback (could be improved with particles, etc) function showFeedback(result, msValue) { var color = 0xffffff; if (result === "marvelous") { color = 0x00fffc; } else if (result === "perfect") { color = 0x00ff00; } else if (result === "good") { color = 0xffff00; } else if (result === "bad") { color = 0xffa500; } else if (result === "fail") { color = 0xff0000; } var msText = ""; if (typeof msValue === "number") { var msAbs = Math.abs(Math.round(msValue)); if (msValue < 0) { msText = " / -" + msAbs + "ms"; } else { msText = " / " + msAbs + "ms"; } } var feedback = new Text2(result.toUpperCase() + msText, { size: 120, fill: "#" + ("000000" + color.toString(16)).slice(-6) }); feedback.anchor.set(0.5, 0); // Place feedback at the top center, below the top bar (avoid top 100px for menu) feedback.x = 2048 / 2; feedback.y = 120; game.addChild(feedback); tween(feedback, { alpha: 0, y: feedback.y - 60 }, { duration: 500 }); LK.setTimeout(function () { feedback.destroy(); }, 500); } self.down = function (x, y, obj) { var now = Date.now(); var msDiff = now - self.hitZoneTime; var absMs = Math.abs(msDiff); var result = "fail"; if (absMs <= MARVELOUS_WINDOW) { result = "marvelous"; marvelousCount++; updateAccuracyDisplay(); } else if (absMs <= PERFECT_WINDOW) { result = "perfect"; perfectCount++; updateAccuracyDisplay(); } else if (absMs <= GOOD_WINDOW) { result = "good"; goodCount++; updateAccuracyDisplay(); } else if (absMs <= BAD_WINDOW) { result = "bad"; badCount++; updateAccuracyDisplay(); } else if (absMs <= FAIL_WINDOW) { result = "fail"; failCount++; updateAccuracyDisplay(); } // If hit is way too early (before hitAccuracy is close), also fail if (now < self.spawnTime + 0.2 * (self.hitZoneTime - self.spawnTime)) { result = "fail"; failCount++; updateAccuracyDisplay(); } LK.getSound('hitSound').play(); showFeedback(result, msDiff); self.destroy(); note = new Note(); game.addChild(note); }; // Miss detection: if player doesn't tap in time, auto-fail self.update = function () { var now = Date.now(); if (now - self.hitZoneTime > FAIL_WINDOW) { failCount++; updateAccuracyDisplay(); showFeedback("fail", undefined); self.destroy(); note = new Note(); game.addChild(note); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var ms; var speed = 1.3; var note; // Hit counters var marvelousCount = 0; var perfectCount = 0; var goodCount = 0; var badCount = 0; var failCount = 0; // Accuracy display texts var accuracyTexts = []; // Helper to create accuracy text objects function createAccuracyText(label, color, yOffset, type) { var txt = new Text2(label + ': 0', { size: 40, fill: color }); txt.anchor.set(1, 0); txt.x = -20; txt.y = yOffset; LK.gui.bottomRight.addChild(txt); accuracyTexts.push({ text: txt, type: type }); return txt; } var marvelousText = createAccuracyText('Marvelous', 0x00FFFC, -280, 'marvelous'); var perfectText = createAccuracyText('Perfect', 0x00FF00, -230, 'perfect'); var goodText = createAccuracyText('Good', 0xFFFF00, -180, 'good'); var badText = createAccuracyText('Bad', 0xFFA500, -130, 'bad'); var failText = createAccuracyText('Fail', 0xFF0000, -80, 'fail'); // Function to update accuracy display function updateAccuracyDisplay() { // Update individual counters marvelousText.setText('Marvelous: ' + marvelousCount); perfectText.setText('Perfect: ' + perfectCount); goodText.setText('Good: ' + goodCount); badText.setText('Bad: ' + badCount); failText.setText('Fail: ' + failCount); // Calculate overall accuracy var totalHits = marvelousCount + perfectCount + goodCount + badCount + failCount; var successfulHits = marvelousCount + perfectCount + goodCount; var accuracy = totalHits > 0 ? Math.round(successfulHits / totalHits * 100) : 0; } /* * Initializations */ note = new Note(); game.addChild(note);
===================================================================
--- original.js
+++ change.js
@@ -67,12 +67,13 @@
color = 0xff0000;
}
var msText = "";
if (typeof msValue === "number") {
+ var msAbs = Math.abs(Math.round(msValue));
if (msValue < 0) {
- msText = " / " + msValue + "ms";
+ msText = " / -" + msAbs + "ms";
} else {
- msText = " / +" + msValue + "ms";
+ msText = " / " + msAbs + "ms";
}
}
var feedback = new Text2(result.toUpperCase() + msText, {
size: 120,