User prompt
AmeĢliore le jeu en mettant le fond du jeu en turquoise, en ajoutant plusieurs notes (une suite de notes), pour le choix de la gamme et en ajoutant des effets sonores au jeu āŖš” Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Accorder les bots
Initial prompt
CreĢe un jeu nommeĢe "Accorder les bots", dans lequel le but est simple : des bots rouges qui chantent faux pparaissent aleĢatoirement a l'eĢcran, et le joueur doit les accorder en appuyant sur un boutton accorder sous chaque bot, et choisir la bonne gamme correspondant aux notes qui s'affichent pour que le bot devienne vert et dispaisse, en disant qu'il chante juste, si le joueur de trompe, le bot reste rouge et disparaiĢt, un message s'affiche disant que c'est pas la bonne gamme, il y a un systeĢme de niveaux, plus le joueur accorde de bots avec succeĢs, plus il monte en niveaux, le joueur niveau 1 doit accorder 5 bots pour atteindre le niveau 2, et a chaque fois ce nombre double pour passer au niveau suivant.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Bot class: represents a singing bot to be tuned var Bot = Container.expand(function () { var self = Container.call(this); // Bot state: 'untuned', 'tuning', 'tuned', 'failed' self.state = 'untuned'; // Randomly pick a sequence of notes and a scale for this bot self.notes = Bot.randomNoteSequence(); self.correctScale = Bot.notesToScale(self.notes); // Create bot body (red box for untuned, green for tuned) self.botAsset = self.attachAsset('botBody', { anchorX: 0.5, anchorY: 0.5 }); self.botAsset.tint = 0xd83318; // red // Display the notes above the bot self.noteText = new Text2(self.notes.join(" "), { size: 90, fill: 0xFFFFFF }); self.noteText.anchor.set(0.5, 1); self.noteText.x = 0; self.noteText.y = -self.botAsset.height / 2 - 20; self.addChild(self.noteText); // "Accorder" button under the bot self.tuneBtn = self.attachAsset('tuneBtn', { anchorX: 0.5, anchorY: 0 }); self.tuneBtn.y = self.botAsset.height / 2 + 30; self.tuneBtn.x = 0; self.addChild(self.tuneBtn); // Button label self.tuneBtnLabel = new Text2("Accorder", { size: 60, fill: 0x222222 }); self.tuneBtnLabel.anchor.set(0.5, 0.5); self.tuneBtnLabel.x = self.tuneBtn.x; self.tuneBtnLabel.y = self.tuneBtn.y + self.tuneBtn.height / 2; self.addChild(self.tuneBtnLabel); // When tuning, show scale choices self.scaleBtns = []; self.scaleBtnLabels = []; // Event: press on "Accorder" button self.tuneBtn.down = function (x, y, obj) { if (self.state !== 'untuned') return; LK.getSound('tune_press').play(); self.showScaleChoices(); }; // Show scale choices under the bot self.showScaleChoices = function () { if (self.state !== 'untuned') return; self.state = 'tuning'; // Remove previous scale buttons if any for (var i = 0; i < self.scaleBtns.length; i++) { self.removeChild(self.scaleBtns[i]); self.removeChild(self.scaleBtnLabels[i]); } self.scaleBtns = []; self.scaleBtnLabels = []; // Get 3 scales: correct + 2 random wrong var scales = Bot.getScaleChoices(self.correctScale); for (var i = 0; i < scales.length; i++) { var btn = self.attachAsset('scaleBtn', { anchorX: 0.5, anchorY: 0 }); btn.x = 0 + (i - 1) * (btn.width + 40); btn.y = self.tuneBtn.y + self.tuneBtn.height + 30; self.addChild(btn); var label = new Text2(scales[i], { size: 55, fill: 0x222222 }); label.anchor.set(0.5, 0.5); label.x = btn.x; label.y = btn.y + btn.height / 2; self.addChild(label); // Closure for scale selection (function (scaleName, btnObj) { btn.down = function (x, y, obj) { self.handleScaleChoice(scaleName); }; })(scales[i], btn); self.scaleBtns.push(btn); self.scaleBtnLabels.push(label); } }; // Handle scale choice self.handleScaleChoice = function (chosenScale) { if (self.state !== 'tuning') return; // Remove scale buttons for (var i = 0; i < self.scaleBtns.length; i++) { self.removeChild(self.scaleBtns[i]); self.removeChild(self.scaleBtnLabels[i]); } self.scaleBtns = []; self.scaleBtnLabels = []; if (chosenScale === self.correctScale) { LK.getSound('tune_success').play(); self.state = 'tuned'; self.botAsset.tint = 0x83de44; // green self.noteText.setText(self.notes.join(" ") + " ā"); // Animate and remove after a short delay tween(self, { alpha: 0 }, { duration: 600, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); onBotTuned(true); } }); } else { LK.getSound('tune_fail').play(); self.state = 'failed'; self.botAsset.tint = 0xd83318; // red self.noteText.setText(self.notes.join(" ") + " ā"); // Animate and remove after a short delay tween(self, { alpha: 0 }, { duration: 600, easing: tween.easeIn, onFinish: function onFinish() { self.destroy(); onBotTuned(false); } }); } }; return self; }); /**** * Initialize Game ****/ // Static: pick a random note var game = new LK.Game({ backgroundColor: 0x008080 // turquoise }); /**** * Game Code ****/ // Static: pick a random note // Asset initialization (shapes for bots and buttons) // Returns a sequence of 2-4 notes (with accidentals) Bot.randomNoteSequence = function () { var notes = ["C", "D", "E", "F", "G", "A", "B"]; var accidentals = ["", "#", "b"]; var len = 2 + Math.floor(Math.random() * 3); // 2-4 notes var seq = []; for (var i = 0; i < len; i++) { var n = notes[Math.floor(Math.random() * notes.length)]; var a = accidentals[Math.floor(Math.random() * accidentals.length)]; seq.push(n + a); } return seq; }; // Map a sequence of notes to a scale (use first note for simplicity) Bot.notesToScale = function (notes) { var base = notes[0][0]; var scales = { "C": "Do majeur", "D": "RĆ© majeur", "E": "Mi majeur", "F": "Fa majeur", "G": "Sol majeur", "A": "La majeur", "B": "Si majeur" }; return scales[base] || "Do majeur"; }; // Static: get 3 scale choices (1 correct, 2 random wrong) Bot.getScaleChoices = function (correct) { var all = ["Do majeur", "RĆ© majeur", "Mi majeur", "Fa majeur", "Sol majeur", "La majeur", "Si majeur"]; var choices = [correct]; // Pick 2 random wrong scales var wrong = []; for (var i = 0; i < all.length; i++) { if (all[i] !== correct) wrong.push(all[i]); } for (var i = 0; i < 2; i++) { var idx = Math.floor(Math.random() * wrong.length); choices.push(wrong[idx]); wrong.splice(idx, 1); } // Shuffle for (var i = choices.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var tmp = choices[i]; choices[i] = choices[j]; choices[j] = tmp; } return choices; }; // Game state var bots = []; var level = 1; var botsToTune = 5; var botsTuned = 0; var botsFailed = 0; var maxBotsOnScreen = 3; var isSpawning = true; // Score/level display var scoreTxt = new Text2("Niveau 1\n0/5 bots accordĆ©s", { size: 90, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Error message var errorMsg = new Text2("", { size: 80, fill: 0xFF3333 }); errorMsg.anchor.set(0.5, 0.5); errorMsg.visible = false; LK.gui.center.addChild(errorMsg); // Called when a bot is tuned or failed function onBotTuned(success) { if (success) { botsTuned++; } else { botsFailed++; showError("Mauvaise gamme !"); } updateScoreText(); // Remove from bots array for (var i = bots.length - 1; i >= 0; i--) { if (bots[i].state === 'tuned' || bots[i].state === 'failed') { bots.splice(i, 1); } } // Check level up if (botsTuned >= botsToTune) { nextLevel(); } } // Show error message for 1s function showError(msg) { errorMsg.setText(msg); errorMsg.visible = true; tween(errorMsg, { alpha: 1 }, { duration: 0 }); LK.setTimeout(function () { tween(errorMsg, { alpha: 0 }, { duration: 400, onFinish: function onFinish() { errorMsg.visible = false; } }); }, 1000); } // Update score/level text function updateScoreText() { scoreTxt.setText("Niveau " + level + "\n" + botsTuned + "/" + botsToTune + " bots accordĆ©s"); } // Level up function nextLevel() { level++; botsTuned = 0; botsFailed = 0; botsToTune = botsToTune * 2; updateScoreText(); // Flash green LK.effects.flashScreen(0x83de44, 600); } // Spawn a bot at a random position function spawnBot() { if (!isSpawning) return; if (bots.length >= maxBotsOnScreen) return; if (botsTuned >= botsToTune) return; var bot = new Bot(); // Place randomly, avoid top 100px and bottom 200px var margin = 120; var minY = 200; var maxY = 2732 - 350; var minX = margin; var maxX = 2048 - margin; bot.x = minX + Math.random() * (maxX - minX); bot.y = minY + Math.random() * (maxY - minY); bots.push(bot); game.addChild(bot); } // Main game update game.update = function () { // Spawn bots as needed if (isSpawning && bots.length < maxBotsOnScreen && botsTuned < botsToTune) { spawnBot(); } // Win condition: after last level, e.g. level 5 (arbitrary cap) if (level > 5) { LK.showYouWin(); isSpawning = false; } }; // Reset game state on game over game.onGameOver = function () { bots = []; level = 1; botsToTune = 5; botsTuned = 0; botsFailed = 0; isSpawning = true; updateScoreText(); errorMsg.visible = false; }; // (Optional) handle resizing, but LK does this automatically // No dragging or movement needed; all interaction is via buttons // End of file
===================================================================
--- original.js
+++ change.js
@@ -10,19 +10,19 @@
var Bot = Container.expand(function () {
var self = Container.call(this);
// Bot state: 'untuned', 'tuning', 'tuned', 'failed'
self.state = 'untuned';
- // Randomly pick a note and a scale for this bot
- self.note = Bot.randomNote();
- self.correctScale = Bot.noteToScale(self.note);
+ // Randomly pick a sequence of notes and a scale for this bot
+ self.notes = Bot.randomNoteSequence();
+ self.correctScale = Bot.notesToScale(self.notes);
// Create bot body (red box for untuned, green for tuned)
self.botAsset = self.attachAsset('botBody', {
anchorX: 0.5,
anchorY: 0.5
});
self.botAsset.tint = 0xd83318; // red
- // Display the note above the bot
- self.noteText = new Text2(self.note, {
+ // Display the notes above the bot
+ self.noteText = new Text2(self.notes.join(" "), {
size: 90,
fill: 0xFFFFFF
});
self.noteText.anchor.set(0.5, 1);
@@ -51,8 +51,9 @@
self.scaleBtnLabels = [];
// Event: press on "Accorder" button
self.tuneBtn.down = function (x, y, obj) {
if (self.state !== 'untuned') return;
+ LK.getSound('tune_press').play();
self.showScaleChoices();
};
// Show scale choices under the bot
self.showScaleChoices = function () {
@@ -103,11 +104,12 @@
}
self.scaleBtns = [];
self.scaleBtnLabels = [];
if (chosenScale === self.correctScale) {
+ LK.getSound('tune_success').play();
self.state = 'tuned';
self.botAsset.tint = 0x83de44; // green
- self.noteText.setText(self.note + " ā");
+ self.noteText.setText(self.notes.join(" ") + " ā");
// Animate and remove after a short delay
tween(self, {
alpha: 0
}, {
@@ -118,11 +120,12 @@
onBotTuned(true);
}
});
} else {
+ LK.getSound('tune_fail').play();
self.state = 'failed';
self.botAsset.tint = 0xd83318; // red
- self.noteText.setText(self.note + " ā");
+ self.noteText.setText(self.notes.join(" ") + " ā");
// Animate and remove after a short delay
tween(self, {
alpha: 0
}, {
@@ -142,28 +145,32 @@
* Initialize Game
****/
// Static: pick a random note
var game = new LK.Game({
- backgroundColor: 0x181818
+ backgroundColor: 0x008080 // turquoise
});
/****
* Game Code
****/
// Static: pick a random note
// Asset initialization (shapes for bots and buttons)
-Bot.randomNote = function () {
- // Use C, D, E, F, G, A, B, with random sharp/flat
+// Returns a sequence of 2-4 notes (with accidentals)
+Bot.randomNoteSequence = function () {
var notes = ["C", "D", "E", "F", "G", "A", "B"];
var accidentals = ["", "#", "b"];
- var n = notes[Math.floor(Math.random() * notes.length)];
- var a = accidentals[Math.floor(Math.random() * accidentals.length)];
- return n + a;
+ var len = 2 + Math.floor(Math.random() * 3); // 2-4 notes
+ var seq = [];
+ for (var i = 0; i < len; i++) {
+ var n = notes[Math.floor(Math.random() * notes.length)];
+ var a = accidentals[Math.floor(Math.random() * accidentals.length)];
+ seq.push(n + a);
+ }
+ return seq;
};
-// Static: map note to a scale (for simplicity, C, D, E, F, G, A, B ā C major, D major, etc)
-Bot.noteToScale = function (note) {
- // Remove accidental for scale name
- var base = note[0];
+// Map a sequence of notes to a scale (use first note for simplicity)
+Bot.notesToScale = function (notes) {
+ var base = notes[0][0];
var scales = {
"C": "Do majeur",
"D": "RĆ© majeur",
"E": "Mi majeur",
Modern App Store icon, high definition, square with rounded corners, for a game titled "Accorder les bots" and with the description "Des bots rouges chantent faux aĢ lāeĢcran. Appuie sur "Accorder", choisis la bonne gamme selon les notes afficheĢes pour accorder chaque bot. Monte de niveau en accordant de plus en plus de bots.". No text on icon!
Fond d'eĢcran salle de programmation. In-Game asset. 2d. High contrast. No shadows