Code edit (1 edits merged)
Please save this source code
User prompt
si no se especifica la posición o si es === 0 que la posición sea random
User prompt
agrega en add note la ubicacion del eje x e y
Code edit (2 edits merged)
Please save this source code
User prompt
Agrega a las Notes un gran numero en el centro en el orden de aparición, cuando el 1 se rompe, el segundo pasa a ser 1
Code edit (1 edits merged)
Please save this source code
User prompt
agrega una forma más comoda visualmente de agregar notas. EN vez de los ticks (500) que sea con el timer (0:01.00)
User prompt
agrea 5 notas random
User prompt
Crea una función reusable para agregar notas manualmente según el tiempo. EJ: note(time)
User prompt
agrega 5 notas random
User prompt
Crea una función reusable para agregar notas manualmente segun el tiempo
Code edit (1 edits merged)
Please save this source code
User prompt
agrega un espaciado justo entre los numeros ara evitar que se muevamn
User prompt
Agrega un contador encima que diga 0:00.00 que vaya subiendo cada segundo
Code edit (1 edits merged)
Please save this source code
User prompt
agrega un timer en la parte superior que vaya aumentando con el tiemo
User prompt
haz que note deje de aparecer al destruirse uno
User prompt
agrega un contador de tiempo que aumente cada segundo
Code edit (1 edits merged)
Please save this source code
User prompt
haz que note deje de aparecer al destruirse uno
Code edit (1 edits merged)
Please save this source code
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
/**** * 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 // Optimized reusable feedback display function function showFeedback(result, msValue) { // Color mapping for feedback var colorMap = { marvelous: 0x00fffc, perfect: 0x00ff00, good: 0xffff00, bad: 0xffa500, fail: 0xff0000 }; var color = colorMap[result] || 0xffffff; // Format msText: always 0 decimals, no + for positive, always show sign for negative var msText = ""; if (typeof msValue === "number") { var msAbs = Math.abs(Math.round(msValue)); msText = " / " + (msValue < 0 ? "-" : "") + 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++; } else if (absMs <= PERFECT_WINDOW) { result = "perfect"; perfectCount++; } else if (absMs <= GOOD_WINDOW) { result = "good"; goodCount++; } else if (absMs <= BAD_WINDOW) { result = "bad"; badCount++; } else if (absMs <= FAIL_WINDOW) { result = "fail"; failCount++; } // 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; var score = 0; var marvelousCount = 0; var perfectCount = 0; var goodCount = 0; var badCount = 0; var failCount = 0; // Accuracy display configuration and storage var accuracyDisplayConfig = [{ label: 'Marvelous', color: 0x00FFFC, yOffset: -280, type: 'marvelous' }, { label: 'Perfect', color: 0x00FF00, yOffset: -230, type: 'perfect' }, { label: 'Good', color: 0xFFFF00, yOffset: -180, type: 'good' }, { label: 'Bad', color: 0xFFA500, yOffset: -130, type: 'bad' }, { label: 'Fail', color: 0xFF0000, yOffset: -80, type: 'fail' }]; var accuracyTexts = {}; function createAccuracyText(label, color, yOffset) { 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); return txt; } accuracyDisplayConfig.forEach(function (cfg) { accuracyTexts[cfg.type] = createAccuracyText(cfg.label, cfg.color, cfg.yOffset); }); function updateAccuracyDisplay() { accuracyTexts.marvelous.setText('Marvelous: ' + marvelousCount); accuracyTexts.perfect.setText('Perfect: ' + perfectCount); accuracyTexts.good.setText('Good: ' + goodCount); accuracyTexts.bad.setText('Bad: ' + badCount); accuracyTexts.fail.setText('Fail: ' + failCount); } /* * Initializations */ note = new Note(); game.addChild(note);
/****
* 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
// Optimized reusable feedback display function
function showFeedback(result, msValue) {
// Color mapping for feedback
var colorMap = {
marvelous: 0x00fffc,
perfect: 0x00ff00,
good: 0xffff00,
bad: 0xffa500,
fail: 0xff0000
};
var color = colorMap[result] || 0xffffff;
// Format msText: always 0 decimals, no + for positive, always show sign for negative
var msText = "";
if (typeof msValue === "number") {
var msAbs = Math.abs(Math.round(msValue));
msText = " / " + (msValue < 0 ? "-" : "") + 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++;
} else if (absMs <= PERFECT_WINDOW) {
result = "perfect";
perfectCount++;
} else if (absMs <= GOOD_WINDOW) {
result = "good";
goodCount++;
} else if (absMs <= BAD_WINDOW) {
result = "bad";
badCount++;
} else if (absMs <= FAIL_WINDOW) {
result = "fail";
failCount++;
}
// 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;
var score = 0;
var marvelousCount = 0;
var perfectCount = 0;
var goodCount = 0;
var badCount = 0;
var failCount = 0;
// Accuracy display configuration and storage
var accuracyDisplayConfig = [{
label: 'Marvelous',
color: 0x00FFFC,
yOffset: -280,
type: 'marvelous'
}, {
label: 'Perfect',
color: 0x00FF00,
yOffset: -230,
type: 'perfect'
}, {
label: 'Good',
color: 0xFFFF00,
yOffset: -180,
type: 'good'
}, {
label: 'Bad',
color: 0xFFA500,
yOffset: -130,
type: 'bad'
}, {
label: 'Fail',
color: 0xFF0000,
yOffset: -80,
type: 'fail'
}];
var accuracyTexts = {};
function createAccuracyText(label, color, yOffset) {
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);
return txt;
}
accuracyDisplayConfig.forEach(function (cfg) {
accuracyTexts[cfg.type] = createAccuracyText(cfg.label, cfg.color, cfg.yOffset);
});
function updateAccuracyDisplay() {
accuracyTexts.marvelous.setText('Marvelous: ' + marvelousCount);
accuracyTexts.perfect.setText('Perfect: ' + perfectCount);
accuracyTexts.good.setText('Good: ' + goodCount);
accuracyTexts.bad.setText('Bad: ' + badCount);
accuracyTexts.fail.setText('Fail: ' + failCount);
}
/*
* Initializations
*/
note = new Note();
game.addChild(note);