Advertisement
Guest User

JavaScript CYS game engine demo

a guest
Apr 16th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. engine.storyName = "CYS JavaScript engine demo";
  2.  
  3. variables({
  4.     vase_alive: true,
  5.     vase_quest: false,
  6.     vase_ask_more: false,
  7.     glass_count: 0,
  8.     snail_location: "yard",
  9.     hunger: 0,
  10.     mosaic: null,
  11.     idleChoices: [0, 1, 2, 3]
  12. });
  13.  
  14. function addHunger() {
  15.     if (++hunger >= 6)
  16.         jumpLink("", ">end", "^You tried to do it, but died of starvation.");
  17. }
  18.  
  19. addScene("intro", "Damn! Your head hurts. <ln> You open your eyes, move your hands and realize that you are lying on a dusty floor. <ln> You can't remember anything.",
  20. "stand up", ">room");
  21.  
  22. addScene("room", function() {
  23.     ln("You are standing in a room with a single open doorway.");
  24.     if (mosaic) {
  25.         ln("There is an image of " + mosaic + " made out of glass on the floor.");
  26.     }else if(vase_alive) {
  27.         ln("A big glass vase is standing on the floor.");
  28.         link("pick up the vase ###", "", "You can't pick up the vase, it is too heavy.");
  29.         link("kick the vase", {vase_alive:false},
  30.             "With a mighty kick you make the vase fall and shatter to many small pieces.");
  31.         if (vase_quest)
  32.             link("talk to the vase #", "", "The vase does not answer.");
  33.     }else {
  34.         ln("Shattered glass is scattered around.");
  35.         link("make a mosaic out of glass on the floor", ">choose image");
  36.         link("pick up a piece of glass", "{glass_count++}",
  37.             "You manage to pick up " + (glass_count ? "another" : "a") + " piece of glass.");
  38.     }
  39.     if (snail_location == "room")
  40.         ln("A snail is crawling on the floor.");
  41.     if (vase_quest && snail_location == "pocket") {
  42.         if (vase_alive)
  43.             link("put the snail into the vase", ">wish");
  44.         else
  45.             link("put the snail near the remains of the vase", {snail_location:"room"});
  46.     }
  47.     link("look around ###", "", "There are no windows. The room is very dusty.");
  48.     link("exit the room", ">yard", "^You came out of the room.");
  49. });
  50.  
  51. addScene("choose image", function() {
  52.     if (state == "") {
  53.         ln("What do you want to depict?");
  54.         link("a skull");
  55.         link("a flower");
  56.         link("a cute elephant", "an ugly elephant");
  57.     }else {
  58.         mosaic = state;
  59.         ln("Making the fine mosic took several hours.");
  60.         addHunger();
  61.         link("next", "<");
  62.     }
  63. });
  64.  
  65. addScene("yard", function() {
  66.     ln("The small shed stands in a yard surrounded by high walls. The yard is covered in grass.");
  67.     link("examine the shed ###", {vase_quest:true},
  68.         "There is a dusty sign above the door. It says: \"I like snails. Bring me one and I'll grant you one wish. Sincerly yours, the Magical Vase.\"");
  69.     link("search for an exit ##", addHunger,
  70.         "You carefully examie every inch of the walls. It seems there is no exit.");
  71.     link("try to climb the walls ###", "",
  72.          "You have tried and failed. There is no way you can climb these walls.");
  73.     if (vase_quest) {
  74.         link("search for snails", addHunger, function() {            
  75.             text = "You spend several hours searching in the grass ";
  76.             if (snail_location == "yard") {
  77.                 text += "and finally pick up a snail.";
  78.                 snail_location = "pocket";
  79.             }else
  80.                 text += "but find no snails."
  81.         });
  82.     }
  83.     link("enter the shed", ">room");
  84. });
  85.  
  86. addScene("wish", function() {
  87.     snail_location = "none";
  88.     ln("\"Thank you staranger!\", the vase speaks. \"I am very pleased. I can't hunt for snails myself. No hands, you know...\" <ln> \"Now choose one wish and I will grant it.\"");
  89.     link("@I want to know what is happening and why I am here.", ">room",
  90.         "@You were teleported here by an evil wisard who has also erased your bemory by hitting your head with a stick. The wish is granted.");
  91.     link("@Get me out of here!", ">end",
  92.         "You were teleported to a big city. A few years later you managed to become a merchat, create a family and live happily ever after. <ln> Until the end of your life you have not learned the mystery of the dusty shed with the Magical Vase.");
  93.     if (vase_ask_more) {
  94.         link("@Create a snail, o mighty Vase!", ">room {snail_location='pocket'}",
  95.              "@Your wish is granted. The new snail is in your right pocket now.");
  96.     }else {
  97.         link("@I wish for more snails!", {vase_ask_more:true},
  98.             "@I'm sorry, I can create only one. Do you want me to do it?");
  99.     }
  100.     link("@I don't have a wish.", ">room",
  101.          "@It's too bad. Thanks for the snail anyway. Farewell.");
  102. });
  103.  
  104. addScene("do nothing", function() {
  105.     addHunger();
  106.     switch(pickShuffle(idleChoices)) {
  107.     case 0: ln("You sit and do nothing for several hours."); break;
  108.     case 1:
  109.         ln("You sleep and have a nightmare.");
  110.         addHunger();
  111.         break;
  112.     case 2: ln("You sit down and think about your miserable existence."); break;
  113.     case 3: ln("You kill some time by thinking about a storygame you can write."); break;
  114.     }
  115. }, "next", "<");
  116.  
  117. addScene("end", function() {
  118.     ln("This is the end.");
  119. },
  120. "try again", "RESTART",
  121. "rate and comment the story", "END");
  122.  
  123. engine.afterText = function() {
  124.     if (scene != "room" && scene != "yard") return;
  125.     switch(hunger) {
  126.     case 2: ln("You feel a light hunger."); break;
  127.     case 3: ln("#o You are hungry."); break;
  128.     case 4: ln("#r You are very hungry."); break;
  129.     case 5:
  130.         ln("#r The hunger is almost unbearable.");
  131.         if (glass_count > 0)
  132.             link("#r cut your veins with a piece of glass",
  133.                 ">end", "^You bleed to death.");
  134.         break;
  135.     }
  136.     if (hunger >= 3 && (snail_location == "pocket" ||
  137.         (scene == "room" && snail_location == "room")))
  138.     {
  139.         link("#g eat the snail",
  140.             function() {
  141.                 hunger = Math.max(hunger-2, 0);
  142.                 snail_location = "none";
  143.             },
  144.             "You crunch the snail along with its shell. It is unexpectedly delicious.");
  145.     }
  146.     link("wait", ">do nothing");
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement