User prompt
Haz las opciones más pequeñas para que se puedan ver todas
User prompt
Extiende las historias hasta llegar al capítulo 5
User prompt
Extiende las historias y haz más finales
User prompt
Haz el texto narrativo más pequeño
User prompt
Haz los botones y los textos el doble de grandes y más separados entre sí
User prompt
Haz los botones más grandes y más separados entre sí
User prompt
Haz los botones más separados entre sí
User prompt
Haz los textos y los botones más grandes
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.storyProgress = {' Line Number: 799 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.storyProgress = {' Line Number: 799 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.storyProgress = {' Line Number: 796 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.storyProgress = {' Line Number: 796 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.storyProgress = {' Line Number: 793
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.storyProgress = {' Line Number: 789 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'chapter')' in or related to this line: 'var chapterText = new Text2(translations[currentLanguage].chapter + ' 1', {' Line Number: 742
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'chapter')' in or related to this line: 'var chapterText = new Text2(translations[currentLanguage].chapter + ' 1', {' Line Number: 742
User prompt
Haz que el juego tenga una opción para cambiarse entre el idioma inglés y el idioma español ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Choose Your Path
Initial prompt
Un juego del estilo "Decide tu propia aventura" donde el jugador va tomando decisiones a medida que va avanzando en el juego, el jugador se va encontrando con diferentes personajes y va descubriendo la historia del mundo. El juego tiene múltiples finales dependiendo de las decisones que tome el jugador.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var ChoiceButton = Container.expand(function (text, callback) { var self = Container.call(this); var buttonBg = self.attachAsset('choiceButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(text, { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.isHovered = false; self.callback = callback; self.down = function (x, y, obj) { if (self.callback) { self.callback(); } }; self.setHover = function (hover) { if (hover && !self.isHovered) { self.isHovered = true; tween(buttonBg, { scaleX: 1.1, scaleY: 1.1 }, { duration: 200 }); buttonBg.tint = 0x533483; } else if (!hover && self.isHovered) { self.isHovered = false; tween(buttonBg, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200 }); buttonBg.tint = 0xffffff; } }; return self; }); var ProgressIndicator = Container.expand(function () { var self = Container.call(this); var progressBg = self.attachAsset('progressBar', { anchorX: 0.5, anchorY: 0.5 }); progressBg.alpha = 0.3; var progressFill = self.attachAsset('progressFill', { anchorX: 0, anchorY: 0.5 }); progressFill.x = -800; self.setProgress = function (percentage) { var targetWidth = 1600 * (percentage / 100); tween(progressFill, { width: targetWidth }, { duration: 500 }); }; return self; }); var StoryPanel = Container.expand(function () { var self = Container.call(this); var panelBg = self.attachAsset('textPanel', { anchorX: 0.5, anchorY: 0.5 }); panelBg.alpha = 0.9; var storyText = new Text2('', { size: 45, fill: 0xFFFFFF }); storyText.anchor.set(0.5, 0.5); self.addChild(storyText); self.setText = function (text) { storyText.setText(text); // Wrap text if too long if (storyText.width > 1700) { var words = text.split(' '); var lines = []; var currentLine = ''; for (var i = 0; i < words.length; i++) { var testLine = currentLine + words[i] + ' '; storyText.setText(testLine); if (storyText.width > 1700 && currentLine !== '') { lines.push(currentLine.trim()); currentLine = words[i] + ' '; } else { currentLine = testLine; } } lines.push(currentLine.trim()); storyText.setText(lines.join('\n')); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0f0f23 }); /**** * Game Code ****/ // Story data structure var storyData = { intro: { text: "You wake up in a mysterious forest. The moonlight filters through ancient trees, casting eerie shadows. You hear distant sounds...", choices: [{ text: "Follow the sounds", next: "sounds" }, { text: "Stay hidden and observe", next: "hidden" }, { text: "Climb a tree for better view", next: "climb" }] }, sounds: { text: "You venture toward the sounds and discover a campfire with a hooded figure sitting alone. They look up as you approach.", choices: [{ text: "Greet them peacefully", next: "peaceful" }, { text: "Ask who they are", next: "suspicious" }, { text: "Back away slowly", next: "retreat" }] }, hidden: { text: "From your hiding spot, you observe strange lights dancing between the trees. They seem to pulse with life.", choices: [{ text: "Investigate the lights", next: "lights" }, { text: "Wait longer", next: "wait" }, { text: "Try to find another path", next: "path" }] }, climb: { text: "From the treetop, you see a vast landscape with a distant castle and what appears to be a village below.", choices: [{ text: "Head toward the castle", next: "castle" }, { text: "Go to the village", next: "village" }, { text: "Explore the forest more", next: "explore" }] }, peaceful: { text: "The figure smiles and offers you food. 'Traveler,' they say, 'you seem lost. I can help you find your way.'", choices: [{ text: "Accept their help", next: "accept_help" }, { text: "Politely decline", next: "decline_help" }] }, suspicious: { text: "The figure chuckles. 'I am someone who has been waiting for you. Your destiny calls, but the path is treacherous.'", choices: [{ text: "Ask about your destiny", next: "destiny" }, { text: "Express doubt", next: "doubt" }] }, retreat: { text: "As you back away, you step on a twig. The figure calls out, 'Don't be afraid! I mean no harm!'", choices: [{ text: "Stop and turn around", next: "turn_around" }, { text: "Continue retreating", next: "continue_retreat" }] }, lights: { text: "The lights are magical fireflies that lead you to an ancient shrine. Strange symbols glow on its surface.", choices: [{ text: "Touch the symbols", next: "symbols" }, { text: "Study them first", next: "study" }] }, wait: { text: "After waiting, you see the lights form a path leading deeper into the forest. It seems like an invitation.", choices: [{ text: "Follow the light path", next: "light_path" }, { text: "Ignore it and leave", next: "ignore" }] }, path: { text: "You find a winding path that leads to a crossroads with three different routes marked by stone markers.", choices: [{ text: "Take the left path", next: "left_path" }, { text: "Take the right path", next: "right_path" }] }, castle: { text: "You reach the castle gates. They're open, but darkness lurks within. This could be the end of your journey.", choices: [{ text: "Enter the castle", next: "ending_castle" }, { text: "Turn back", next: "ending_retreat" }] }, village: { text: "In the village, friendly people welcome you. You've found a new home and community.", choices: [{ text: "Stay with the villagers", next: "ending_village" }] }, explore: { text: "Deep in the forest, you discover ancient ruins that hold the secrets of this mysterious world.", choices: [{ text: "Become the guardian", next: "ending_guardian" }] }, accept_help: { text: "With their guidance, you find your way back to civilization and start a new chapter in your life.", choices: [{ text: "Begin your new life", next: "ending_new_life" }] }, decline_help: { text: "You thank them but choose to forge your own path, learning independence and self-reliance.", choices: [{ text: "Continue alone", next: "ending_independent" }] }, destiny: { text: "They reveal you're the chosen one who must save this realm. You accept the responsibility.", choices: [{ text: "Embrace your destiny", next: "ending_hero" }] }, doubt: { text: "Your skepticism proves wise. You discover they were testing your judgment. You pass their test.", choices: [{ text: "Accept their wisdom", next: "ending_wise" }] }, turn_around: { text: "You return and learn they're a helpful spirit guide who leads you to safety.", choices: [{ text: "Follow the spirit", next: "ending_guided" }] }, continue_retreat: { text: "You escape but remain lost in the forest forever, becoming part of its mystery.", choices: [{ text: "Accept your fate", next: "ending_lost" }] }, symbols: { text: "Touching the symbols grants you magical powers. You become a forest protector.", choices: [{ text: "Protect the forest", next: "ending_protector" }] }, study: { text: "Your careful study reveals the shrine's secrets without triggering any traps.", choices: [{ text: "Use the knowledge", next: "ending_scholar" }] }, light_path: { text: "The light path leads you to a realm of eternal beauty where you find true happiness.", choices: [{ text: "Stay in paradise", next: "ending_paradise" }] }, ignore: { text: "You leave the forest but always wonder what could have been. You live with regret.", choices: [{ text: "Live with uncertainty", next: "ending_regret" }] }, left_path: { text: "The left path leads to a hidden treasure that makes you wealthy beyond measure.", choices: [{ text: "Claim the treasure", next: "ending_wealthy" }] }, right_path: { text: "The right path brings you to a wise sage who teaches you the meaning of life.", choices: [{ text: "Learn from the sage", next: "ending_enlightened" }] }, // Endings ending_castle: { text: "You enter the castle and become its new ruler, bringing light to the darkness.", isEnding: true }, ending_retreat: { text: "You choose safety over adventure and return home, valuing caution over curiosity.", isEnding: true }, ending_village: { text: "You find happiness in simple community life, surrounded by friends and purpose.", isEnding: true }, ending_guardian: { text: "You become the eternal guardian of ancient secrets, protecting them for future generations.", isEnding: true }, ending_new_life: { text: "With help from others, you build a successful and fulfilling new life in civilization.", isEnding: true }, ending_independent: { text: "Your self-reliance leads to great personal growth and eventual success on your own terms.", isEnding: true }, ending_hero: { text: "You embrace your role as the chosen one and save the realm, becoming a legendary hero.", isEnding: true }, ending_wise: { text: "Your wisdom and caution are rewarded with knowledge and respect from the mystical beings.", isEnding: true }, ending_guided: { text: "The spirit guide leads you to enlightenment and you become a bridge between worlds.", isEnding: true }, ending_lost: { text: "You become part of the forest's eternal mystery, your story inspiring future travelers.", isEnding: true }, ending_protector: { text: "With magical powers, you protect the forest and its creatures for eternity.", isEnding: true }, ending_scholar: { text: "Your knowledge of the ancient symbols makes you a renowned scholar and historian.", isEnding: true }, ending_paradise: { text: "You find eternal happiness in the magical realm, living in perfect harmony.", isEnding: true }, ending_regret: { text: "You return to normal life but are forever changed by the mysterious encounter.", isEnding: true }, ending_wealthy: { text: "The treasure makes you rich, and you use your wealth to help others find their paths.", isEnding: true }, ending_enlightened: { text: "The sage's wisdom transforms you into a teacher who helps others find meaning.", isEnding: true } }; // Game state var currentStoryNode = 'intro'; var storyHistory = []; var totalNodes = Object.keys(storyData).length; var visitedNodes = 0; // UI Elements var background = game.attachAsset('storyBackground', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 }); var storyPanel = game.addChild(new StoryPanel()); storyPanel.x = 1024; storyPanel.y = 800; var progressIndicator = game.addChild(new ProgressIndicator()); progressIndicator.x = 1024; progressIndicator.y = 150; var choiceButtons = []; // Chapter indicator var chapterText = new Text2('Chapter 1', { size: 50, fill: 0xE94560 }); chapterText.anchor.set(0.5, 0); chapterText.x = 1024; chapterText.y = 200; game.addChild(chapterText); // Load saved progress var savedProgress = storage.storyProgress || {}; if (savedProgress.currentNode) { currentStoryNode = savedProgress.currentNode; storyHistory = savedProgress.history || []; visitedNodes = savedProgress.visitedNodes || 0; } function updateProgress() { var progressPercentage = visitedNodes / totalNodes * 100; progressIndicator.setProgress(progressPercentage); var chapterNumber = Math.floor(visitedNodes / 3) + 1; chapterText.setText('Chapter ' + chapterNumber); } function clearChoices() { for (var i = 0; i < choiceButtons.length; i++) { choiceButtons[i].destroy(); } choiceButtons = []; } function makeChoice(nextNode) { storyHistory.push(currentStoryNode); currentStoryNode = nextNode; visitedNodes++; // Save progress storage.storyProgress = { currentNode: currentStoryNode, history: storyHistory, visitedNodes: visitedNodes }; updateProgress(); displayCurrentStory(); } function displayCurrentStory() { var storyNode = storyData[currentStoryNode]; // Animate text appearance storyPanel.alpha = 0; storyPanel.setText(storyNode.text); tween(storyPanel, { alpha: 1 }, { duration: 1000 }); clearChoices(); if (storyNode.isEnding) { // Show ending var restartButton = game.addChild(new ChoiceButton('Start New Story', function () { // Reset game currentStoryNode = 'intro'; storyHistory = []; visitedNodes = 0; storage.storyProgress = {}; updateProgress(); displayCurrentStory(); })); restartButton.x = 1024; restartButton.y = 1500; choiceButtons.push(restartButton); // Update score based on ending var endingScore = visitedNodes * 10; LK.setScore(endingScore); // Show completion message LK.setTimeout(function () { LK.showYouWin(); }, 2000); } else { // Show choices var choices = storyNode.choices; var startY = 1400; var spacing = 150; for (var i = 0; i < choices.length; i++) { var choice = choices[i]; var button = game.addChild(new ChoiceButton(choice.text, function (nextNode) { return function () { makeChoice(nextNode); }; }(choice.next))); button.x = 1024; button.y = startY + i * spacing; button.alpha = 0; choiceButtons.push(button); // Animate button appearance tween(button, { alpha: 1 }, { duration: 500, easing: tween.easeOut }); } } } // Mouse interaction for button hover effects game.move = function (x, y, obj) { for (var i = 0; i < choiceButtons.length; i++) { var button = choiceButtons[i]; var distance = Math.sqrt(Math.pow(x - button.x, 2) + Math.pow(y - button.y, 2)); button.setHover(distance < 250); } }; // Initialize the game updateProgress(); displayCurrentStory();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,537 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var ChoiceButton = Container.expand(function (text, callback) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('choiceButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(text, {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.isHovered = false;
+ self.callback = callback;
+ self.down = function (x, y, obj) {
+ if (self.callback) {
+ self.callback();
+ }
+ };
+ self.setHover = function (hover) {
+ if (hover && !self.isHovered) {
+ self.isHovered = true;
+ tween(buttonBg, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 200
+ });
+ buttonBg.tint = 0x533483;
+ } else if (!hover && self.isHovered) {
+ self.isHovered = false;
+ tween(buttonBg, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200
+ });
+ buttonBg.tint = 0xffffff;
+ }
+ };
+ return self;
+});
+var ProgressIndicator = Container.expand(function () {
+ var self = Container.call(this);
+ var progressBg = self.attachAsset('progressBar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ progressBg.alpha = 0.3;
+ var progressFill = self.attachAsset('progressFill', {
+ anchorX: 0,
+ anchorY: 0.5
+ });
+ progressFill.x = -800;
+ self.setProgress = function (percentage) {
+ var targetWidth = 1600 * (percentage / 100);
+ tween(progressFill, {
+ width: targetWidth
+ }, {
+ duration: 500
+ });
+ };
+ return self;
+});
+var StoryPanel = Container.expand(function () {
+ var self = Container.call(this);
+ var panelBg = self.attachAsset('textPanel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ panelBg.alpha = 0.9;
+ var storyText = new Text2('', {
+ size: 45,
+ fill: 0xFFFFFF
+ });
+ storyText.anchor.set(0.5, 0.5);
+ self.addChild(storyText);
+ self.setText = function (text) {
+ storyText.setText(text);
+ // Wrap text if too long
+ if (storyText.width > 1700) {
+ var words = text.split(' ');
+ var lines = [];
+ var currentLine = '';
+ for (var i = 0; i < words.length; i++) {
+ var testLine = currentLine + words[i] + ' ';
+ storyText.setText(testLine);
+ if (storyText.width > 1700 && currentLine !== '') {
+ lines.push(currentLine.trim());
+ currentLine = words[i] + ' ';
+ } else {
+ currentLine = testLine;
+ }
+ }
+ lines.push(currentLine.trim());
+ storyText.setText(lines.join('\n'));
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x0f0f23
+});
+
+/****
+* Game Code
+****/
+// Story data structure
+var storyData = {
+ intro: {
+ text: "You wake up in a mysterious forest. The moonlight filters through ancient trees, casting eerie shadows. You hear distant sounds...",
+ choices: [{
+ text: "Follow the sounds",
+ next: "sounds"
+ }, {
+ text: "Stay hidden and observe",
+ next: "hidden"
+ }, {
+ text: "Climb a tree for better view",
+ next: "climb"
+ }]
+ },
+ sounds: {
+ text: "You venture toward the sounds and discover a campfire with a hooded figure sitting alone. They look up as you approach.",
+ choices: [{
+ text: "Greet them peacefully",
+ next: "peaceful"
+ }, {
+ text: "Ask who they are",
+ next: "suspicious"
+ }, {
+ text: "Back away slowly",
+ next: "retreat"
+ }]
+ },
+ hidden: {
+ text: "From your hiding spot, you observe strange lights dancing between the trees. They seem to pulse with life.",
+ choices: [{
+ text: "Investigate the lights",
+ next: "lights"
+ }, {
+ text: "Wait longer",
+ next: "wait"
+ }, {
+ text: "Try to find another path",
+ next: "path"
+ }]
+ },
+ climb: {
+ text: "From the treetop, you see a vast landscape with a distant castle and what appears to be a village below.",
+ choices: [{
+ text: "Head toward the castle",
+ next: "castle"
+ }, {
+ text: "Go to the village",
+ next: "village"
+ }, {
+ text: "Explore the forest more",
+ next: "explore"
+ }]
+ },
+ peaceful: {
+ text: "The figure smiles and offers you food. 'Traveler,' they say, 'you seem lost. I can help you find your way.'",
+ choices: [{
+ text: "Accept their help",
+ next: "accept_help"
+ }, {
+ text: "Politely decline",
+ next: "decline_help"
+ }]
+ },
+ suspicious: {
+ text: "The figure chuckles. 'I am someone who has been waiting for you. Your destiny calls, but the path is treacherous.'",
+ choices: [{
+ text: "Ask about your destiny",
+ next: "destiny"
+ }, {
+ text: "Express doubt",
+ next: "doubt"
+ }]
+ },
+ retreat: {
+ text: "As you back away, you step on a twig. The figure calls out, 'Don't be afraid! I mean no harm!'",
+ choices: [{
+ text: "Stop and turn around",
+ next: "turn_around"
+ }, {
+ text: "Continue retreating",
+ next: "continue_retreat"
+ }]
+ },
+ lights: {
+ text: "The lights are magical fireflies that lead you to an ancient shrine. Strange symbols glow on its surface.",
+ choices: [{
+ text: "Touch the symbols",
+ next: "symbols"
+ }, {
+ text: "Study them first",
+ next: "study"
+ }]
+ },
+ wait: {
+ text: "After waiting, you see the lights form a path leading deeper into the forest. It seems like an invitation.",
+ choices: [{
+ text: "Follow the light path",
+ next: "light_path"
+ }, {
+ text: "Ignore it and leave",
+ next: "ignore"
+ }]
+ },
+ path: {
+ text: "You find a winding path that leads to a crossroads with three different routes marked by stone markers.",
+ choices: [{
+ text: "Take the left path",
+ next: "left_path"
+ }, {
+ text: "Take the right path",
+ next: "right_path"
+ }]
+ },
+ castle: {
+ text: "You reach the castle gates. They're open, but darkness lurks within. This could be the end of your journey.",
+ choices: [{
+ text: "Enter the castle",
+ next: "ending_castle"
+ }, {
+ text: "Turn back",
+ next: "ending_retreat"
+ }]
+ },
+ village: {
+ text: "In the village, friendly people welcome you. You've found a new home and community.",
+ choices: [{
+ text: "Stay with the villagers",
+ next: "ending_village"
+ }]
+ },
+ explore: {
+ text: "Deep in the forest, you discover ancient ruins that hold the secrets of this mysterious world.",
+ choices: [{
+ text: "Become the guardian",
+ next: "ending_guardian"
+ }]
+ },
+ accept_help: {
+ text: "With their guidance, you find your way back to civilization and start a new chapter in your life.",
+ choices: [{
+ text: "Begin your new life",
+ next: "ending_new_life"
+ }]
+ },
+ decline_help: {
+ text: "You thank them but choose to forge your own path, learning independence and self-reliance.",
+ choices: [{
+ text: "Continue alone",
+ next: "ending_independent"
+ }]
+ },
+ destiny: {
+ text: "They reveal you're the chosen one who must save this realm. You accept the responsibility.",
+ choices: [{
+ text: "Embrace your destiny",
+ next: "ending_hero"
+ }]
+ },
+ doubt: {
+ text: "Your skepticism proves wise. You discover they were testing your judgment. You pass their test.",
+ choices: [{
+ text: "Accept their wisdom",
+ next: "ending_wise"
+ }]
+ },
+ turn_around: {
+ text: "You return and learn they're a helpful spirit guide who leads you to safety.",
+ choices: [{
+ text: "Follow the spirit",
+ next: "ending_guided"
+ }]
+ },
+ continue_retreat: {
+ text: "You escape but remain lost in the forest forever, becoming part of its mystery.",
+ choices: [{
+ text: "Accept your fate",
+ next: "ending_lost"
+ }]
+ },
+ symbols: {
+ text: "Touching the symbols grants you magical powers. You become a forest protector.",
+ choices: [{
+ text: "Protect the forest",
+ next: "ending_protector"
+ }]
+ },
+ study: {
+ text: "Your careful study reveals the shrine's secrets without triggering any traps.",
+ choices: [{
+ text: "Use the knowledge",
+ next: "ending_scholar"
+ }]
+ },
+ light_path: {
+ text: "The light path leads you to a realm of eternal beauty where you find true happiness.",
+ choices: [{
+ text: "Stay in paradise",
+ next: "ending_paradise"
+ }]
+ },
+ ignore: {
+ text: "You leave the forest but always wonder what could have been. You live with regret.",
+ choices: [{
+ text: "Live with uncertainty",
+ next: "ending_regret"
+ }]
+ },
+ left_path: {
+ text: "The left path leads to a hidden treasure that makes you wealthy beyond measure.",
+ choices: [{
+ text: "Claim the treasure",
+ next: "ending_wealthy"
+ }]
+ },
+ right_path: {
+ text: "The right path brings you to a wise sage who teaches you the meaning of life.",
+ choices: [{
+ text: "Learn from the sage",
+ next: "ending_enlightened"
+ }]
+ },
+ // Endings
+ ending_castle: {
+ text: "You enter the castle and become its new ruler, bringing light to the darkness.",
+ isEnding: true
+ },
+ ending_retreat: {
+ text: "You choose safety over adventure and return home, valuing caution over curiosity.",
+ isEnding: true
+ },
+ ending_village: {
+ text: "You find happiness in simple community life, surrounded by friends and purpose.",
+ isEnding: true
+ },
+ ending_guardian: {
+ text: "You become the eternal guardian of ancient secrets, protecting them for future generations.",
+ isEnding: true
+ },
+ ending_new_life: {
+ text: "With help from others, you build a successful and fulfilling new life in civilization.",
+ isEnding: true
+ },
+ ending_independent: {
+ text: "Your self-reliance leads to great personal growth and eventual success on your own terms.",
+ isEnding: true
+ },
+ ending_hero: {
+ text: "You embrace your role as the chosen one and save the realm, becoming a legendary hero.",
+ isEnding: true
+ },
+ ending_wise: {
+ text: "Your wisdom and caution are rewarded with knowledge and respect from the mystical beings.",
+ isEnding: true
+ },
+ ending_guided: {
+ text: "The spirit guide leads you to enlightenment and you become a bridge between worlds.",
+ isEnding: true
+ },
+ ending_lost: {
+ text: "You become part of the forest's eternal mystery, your story inspiring future travelers.",
+ isEnding: true
+ },
+ ending_protector: {
+ text: "With magical powers, you protect the forest and its creatures for eternity.",
+ isEnding: true
+ },
+ ending_scholar: {
+ text: "Your knowledge of the ancient symbols makes you a renowned scholar and historian.",
+ isEnding: true
+ },
+ ending_paradise: {
+ text: "You find eternal happiness in the magical realm, living in perfect harmony.",
+ isEnding: true
+ },
+ ending_regret: {
+ text: "You return to normal life but are forever changed by the mysterious encounter.",
+ isEnding: true
+ },
+ ending_wealthy: {
+ text: "The treasure makes you rich, and you use your wealth to help others find their paths.",
+ isEnding: true
+ },
+ ending_enlightened: {
+ text: "The sage's wisdom transforms you into a teacher who helps others find meaning.",
+ isEnding: true
+ }
+};
+// Game state
+var currentStoryNode = 'intro';
+var storyHistory = [];
+var totalNodes = Object.keys(storyData).length;
+var visitedNodes = 0;
+// UI Elements
+var background = game.attachAsset('storyBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 1366
+});
+var storyPanel = game.addChild(new StoryPanel());
+storyPanel.x = 1024;
+storyPanel.y = 800;
+var progressIndicator = game.addChild(new ProgressIndicator());
+progressIndicator.x = 1024;
+progressIndicator.y = 150;
+var choiceButtons = [];
+// Chapter indicator
+var chapterText = new Text2('Chapter 1', {
+ size: 50,
+ fill: 0xE94560
+});
+chapterText.anchor.set(0.5, 0);
+chapterText.x = 1024;
+chapterText.y = 200;
+game.addChild(chapterText);
+// Load saved progress
+var savedProgress = storage.storyProgress || {};
+if (savedProgress.currentNode) {
+ currentStoryNode = savedProgress.currentNode;
+ storyHistory = savedProgress.history || [];
+ visitedNodes = savedProgress.visitedNodes || 0;
+}
+function updateProgress() {
+ var progressPercentage = visitedNodes / totalNodes * 100;
+ progressIndicator.setProgress(progressPercentage);
+ var chapterNumber = Math.floor(visitedNodes / 3) + 1;
+ chapterText.setText('Chapter ' + chapterNumber);
+}
+function clearChoices() {
+ for (var i = 0; i < choiceButtons.length; i++) {
+ choiceButtons[i].destroy();
+ }
+ choiceButtons = [];
+}
+function makeChoice(nextNode) {
+ storyHistory.push(currentStoryNode);
+ currentStoryNode = nextNode;
+ visitedNodes++;
+ // Save progress
+ storage.storyProgress = {
+ currentNode: currentStoryNode,
+ history: storyHistory,
+ visitedNodes: visitedNodes
+ };
+ updateProgress();
+ displayCurrentStory();
+}
+function displayCurrentStory() {
+ var storyNode = storyData[currentStoryNode];
+ // Animate text appearance
+ storyPanel.alpha = 0;
+ storyPanel.setText(storyNode.text);
+ tween(storyPanel, {
+ alpha: 1
+ }, {
+ duration: 1000
+ });
+ clearChoices();
+ if (storyNode.isEnding) {
+ // Show ending
+ var restartButton = game.addChild(new ChoiceButton('Start New Story', function () {
+ // Reset game
+ currentStoryNode = 'intro';
+ storyHistory = [];
+ visitedNodes = 0;
+ storage.storyProgress = {};
+ updateProgress();
+ displayCurrentStory();
+ }));
+ restartButton.x = 1024;
+ restartButton.y = 1500;
+ choiceButtons.push(restartButton);
+ // Update score based on ending
+ var endingScore = visitedNodes * 10;
+ LK.setScore(endingScore);
+ // Show completion message
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 2000);
+ } else {
+ // Show choices
+ var choices = storyNode.choices;
+ var startY = 1400;
+ var spacing = 150;
+ for (var i = 0; i < choices.length; i++) {
+ var choice = choices[i];
+ var button = game.addChild(new ChoiceButton(choice.text, function (nextNode) {
+ return function () {
+ makeChoice(nextNode);
+ };
+ }(choice.next)));
+ button.x = 1024;
+ button.y = startY + i * spacing;
+ button.alpha = 0;
+ choiceButtons.push(button);
+ // Animate button appearance
+ tween(button, {
+ alpha: 1
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ }
+ }
+}
+// Mouse interaction for button hover effects
+game.move = function (x, y, obj) {
+ for (var i = 0; i < choiceButtons.length; i++) {
+ var button = choiceButtons[i];
+ var distance = Math.sqrt(Math.pow(x - button.x, 2) + Math.pow(y - button.y, 2));
+ button.setHover(distance < 250);
+ }
+};
+// Initialize the game
+updateProgress();
+displayCurrentStory();
\ No newline at end of file