a munch adventure
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

226 líneas
5.4 KiB

  1. "use strict"
  2. let activeModal = null;
  3. const newline = String.fromCharCode(160);
  4. const version = "0.1.2";
  5. let state;
  6. let refreshHook;
  7. const tags = {
  8. "prey": {
  9. name: "Prey",
  10. desc: "You can be eaten in this story"
  11. },
  12. "pred": {
  13. name: "Predator",
  14. desc: "You can eat others in this story"
  15. },
  16. "fatal": {
  17. name: "Fatal Vore",
  18. desc: "Vore may result in death"
  19. },
  20. "non-fatal": {
  21. name: "Non-Fatal Vore",
  22. desc: "Vore may result in endo or other safe outcomes"
  23. },
  24. "soft-digestion": {
  25. name: "Soft Digestion",
  26. desc: "Non-graphic depictions of digestion"
  27. },
  28. "hard-digestion": {
  29. name: "Hard Digestion",
  30. desc: "Gory, gross digestion"
  31. },
  32. "oral-vore": {
  33. name: "Oral Vore",
  34. desc: "The classic"
  35. },
  36. "hard-vore": {
  37. name: "Hard Vore",
  38. desc: "Biting, chewing, and other gory means of consumption"
  39. },
  40. "macro-micro": {
  41. name: "Macro/Micro",
  42. desc: "Characters will have significant size differences"
  43. }
  44. };
  45. function print(lines) {
  46. (lines.concat([newline])).forEach(line => {
  47. const log = document.querySelector("#log");
  48. const div = document.createElement("div");
  49. div.textContent = line;
  50. log.appendChild(div);
  51. });
  52. log.scrollTop = log.scrollHeight;
  53. }
  54. function printRandom(list) {
  55. let choice = Math.floor(Math.random() * list.length)
  56. print(list[choice])
  57. }
  58. function refresh() {
  59. updateRoom(state);
  60. updateStatDisplay(state.info, "world");
  61. updateStatDisplay(state.player.stats, "player");
  62. updateStatDisplay(state.world[state.player.location].data.stats, "area");
  63. if (refreshHook) {
  64. refreshHook(state)
  65. }
  66. }
  67. function switchModal(to) {
  68. closeModal(activeModal);
  69. openModal(to);
  70. }
  71. function closeModal(modal) {
  72. const div = document.querySelector("#" + modal);
  73. div.classList.remove("modal");
  74. div.classList.add("hidden-modal");
  75. }
  76. function openModal(modal) {
  77. const div = document.querySelector("#" + modal);
  78. div.classList.remove("hidden-modal");
  79. div.classList.add("modal");
  80. activeModal = modal;
  81. }
  82. function returnToStart() {
  83. stopAllSound();
  84. stopAllTimers(state);
  85. setBackgroundColor(0, 0, 0);
  86. log.innerHTML = "";
  87. document.querySelector("#game").classList.remove("scene");
  88. document.querySelector("#game").classList.add("hidden-scene");
  89. document.querySelector("#pick").classList.remove("hidden-scene");
  90. document.querySelector("#pick").classList.add("scene");
  91. }
  92. // set up the game
  93. function init(story) {
  94. state = {
  95. player: {
  96. items: {
  97. keys: [
  98. ]
  99. },
  100. rooms: {
  101. },
  102. flags: {
  103. }
  104. },
  105. };
  106. initWorld(story);
  107. initGame(story);
  108. story.intro.setup();
  109. initGamePostSetup();
  110. refreshHook = story.refresh;
  111. story.intro.intro();
  112. goToRoom(story.intro.start);
  113. }
  114. // set up the load screen
  115. function initStart() {
  116. const versionFields = document.querySelectorAll(".version");
  117. const select = document.querySelector("#game-select");
  118. const options = {};
  119. versionFields.forEach(field => {
  120. field.textContent = "Version: " + version;
  121. });
  122. stories.forEach(story => {
  123. const option = document.createElement("option");
  124. option.value = story.id;
  125. option.textContent = story.info.name;
  126. select.appendChild(option);
  127. options[story.id] = story;
  128. })
  129. select.addEventListener("change", event => {
  130. const holder = document.querySelector("#tags");
  131. holder.innerHTML = "";
  132. const story = stories.filter(s => s.id == [event.target.value])[0];
  133. initAudio(story);
  134. story.preload.forEach(sound => loadAudio(sound));
  135. story.info.tags.forEach(tag => {
  136. const div = document.createElement("div");
  137. div.textContent = tags[tag].name;
  138. div.dataset.tooltip = tags[tag].desc;
  139. div.classList.add("tag");
  140. div.classList.add("tooltip");
  141. holder.appendChild(div);
  142. })
  143. });
  144. const start = document.querySelector("#start-button");
  145. start.addEventListener("click", (event) => {
  146. init(options[select.value]);
  147. document.querySelector("#pick").classList.remove("scene");
  148. document.querySelector("#pick").classList.add("hidden-scene");
  149. document.querySelector("#game").classList.remove("hidden-scene");
  150. document.querySelector("#game").classList.add("scene");
  151. });
  152. const gameMenuButton = document.querySelector("#game-menu-button");
  153. const menuSettings = document.querySelector("#menu-button-settings");
  154. const menuQuit = document.querySelector("#menu-button-quit");
  155. const menuResume = document.querySelector("#menu-button-resume");
  156. const menuSettingsVolume = document.querySelector("#menu-slider-volume");
  157. const menuSettingsClose = document.querySelector("#menu-button-settings-close");
  158. const menuQuitYes = document.querySelector("#menu-button-quit-yes");
  159. const menuQuitNo = document.querySelector("#menu-button-quit-no");
  160. gameMenuButton.addEventListener("click", () => openModal("menu"));
  161. menuSettings.addEventListener("click", () => switchModal("settings"));
  162. menuQuit.addEventListener("click", () => switchModal("quit"));
  163. menuResume.addEventListener("click", () => closeModal("menu"));
  164. menuSettingsVolume.addEventListener("input", () => {
  165. setVolume(parseFloat(menuSettingsVolume.value));
  166. })
  167. menuSettingsClose.addEventListener("click", () => switchModal("menu"));
  168. menuQuitYes.addEventListener("click", () => {
  169. closeModal("quit");
  170. returnToStart();
  171. });
  172. menuQuitNo.addEventListener("click", () => switchModal("menu"));
  173. }
  174. window.addEventListener("load", initStart);