big steppy
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

291 linhas
7.0 KiB

  1. var baseHeight = 3.65;
  2. var baseMass = 1360;
  3. var scale = 1;
  4. var strolling = false;
  5. var maxStomachDigest = 10;
  6. var maxBowelsDigest = 10;
  7. var metric = true;
  8. victims = {};
  9. function toggle_auto()
  10. {
  11. strolling = !strolling;
  12. document.getElementById("strolling-indicator").innerHTML = strolling ? "Strolling" : "Standing";
  13. if (strolling)
  14. update(["You start walking."]);
  15. else
  16. update(["You stop walking."]);
  17. }
  18. function toggle_units()
  19. {
  20. metric = !metric;
  21. document.getElementById("button-units").innerHTML = metric ? "Metric" : "Customary";
  22. update();
  23. }
  24. function initVictims()
  25. {
  26. return {
  27. "Person": 0,
  28. "Car": 0,
  29. "Bus": 0,
  30. "Tram": 0,
  31. "Motorcycle": 0,
  32. "House": 0,
  33. "Small Skyscraper": 0,
  34. "Train": 0,
  35. "Train Car": 0,
  36. "Parking Garage": 0,
  37. "Overpass": 0,
  38. };
  39. };
  40. // lists out total people
  41. function summarize(sum, fatal = true)
  42. {
  43. return "(" + sum["Person"] + " " + (fatal ? (sum["Person"] > 1 ? "kills" : "kill") : (sum["Person"] > 1 ? "people" : "person")) + ")";
  44. }
  45. var stomach = []
  46. var bowels = []
  47. function getOnePrey(area)
  48. {
  49. var potential = ["Person", "Car", "Bus", "Tram", "House", "Train", "Parking Garage", "Small Skyscraper"];
  50. var potAreas = []
  51. potential.forEach(function (x) {
  52. potAreas.push([x,areas[x]]);
  53. });
  54. potAreas = potAreas.sort(function (x,y) {
  55. return x[1] < y[1];
  56. });
  57. for (var i=0; i<potAreas.length; i++) {
  58. x = potAreas[i];
  59. if (x[1] < area) {
  60. return new things[x[0]](1);
  61. }
  62. };
  63. return new Person(1);
  64. }
  65. function getPrey(region, area)
  66. {
  67. switch(region)
  68. {
  69. case "suburb": return suburbPrey(area);
  70. }
  71. }
  72. function suburbPrey(area)
  73. {
  74. return fill_area2(area, {"Person": 0.5, "House": 0.5, "Car": 0.2, "Tram": 0.1, "Bus": 0.1, "Small Skyscraper": 0.05, "Parking Garage": 0.02, "Train": 0.05});
  75. }
  76. function updateVictims(type,prey)
  77. {
  78. var sums = prey.sum();
  79. for (var key in sums) {
  80. if (sums.hasOwnProperty(key)) {
  81. victims[type][key] += sums[key];
  82. }
  83. }
  84. }
  85. function scaleAddMass(scale, baseMass, mass)
  86. {
  87. var startMass = Math.pow(scale, 3) * baseMass;
  88. var newMass = startMass + mass;
  89. return Math.pow(newMass / baseMass, 1/3) ;
  90. }
  91. function feed()
  92. {
  93. var prey = getPrey("suburb", 0.5*scale*scale);
  94. var line = prey.eat() + " " + summarize(prey.sum(), false);
  95. var preyMass = prey.sum_property("mass");
  96. scale = scaleAddMass(scale, baseMass, preyMass);
  97. stomach.push(prey);
  98. if (stomach.length == 1)
  99. setTimeout(function() { doDigest("stomach"); }, 15000);
  100. updateVictims("stomach",prey);
  101. update([line]);
  102. }
  103. function stomp()
  104. {
  105. var prey = getPrey("suburb", 1.5*scale*scale);
  106. var line = prey.stomp() + " " + summarize(prey.sum(), true);
  107. var preyMass = prey.sum_property("mass");
  108. scale = scaleAddMass(scale, baseMass, preyMass);
  109. updateVictims("stomped",prey);
  110. update([line]);
  111. }
  112. function anal_vore()
  113. {
  114. var prey = getOnePrey(0.25*scale*scale);
  115. var crushed = getPrey("suburb",3*scale*scale);
  116. var line1 = prey.anal_vore(baseHeight*scale) + " " + summarize(prey.sum(), false);
  117. var line2 = crushed.buttcrush() + " " + summarize(crushed.sum(), false)
  118. var preyMass = prey.sum_property("mass");
  119. var crushedMass = prey.sum_property("mass");
  120. scale = scaleAddMass(scale, baseMass, preyMass);
  121. scale = scaleAddMass(scale, baseMass, crushedMass);
  122. bowels.push(prey);
  123. if (bowels.length == 1)
  124. setTimeout(function() { doDigest("bowels"); }, 15000);
  125. updateVictims("bowels",prey);
  126. updateVictims("stomped",crushed);
  127. update([line1,line2]);
  128. }
  129. function update(lines = [])
  130. {
  131. var log = document.getElementById("log");
  132. lines.forEach(function (x) {
  133. var line = document.createElement('div');
  134. line.innerHTML = x;
  135. log.appendChild(line);
  136. });
  137. log.scrollTop = log.scrollHeight;
  138. var height = baseHeight * scale;
  139. var mass = baseMass * Math.pow(scale, 3);
  140. document.getElementById("height").innerHTML = "Height: " + (metric ? metricLength(height) : customaryLength(height));
  141. document.getElementById("mass").innerHTML = "Mass: " + (metric ? metricMass(mass) : customaryMass(mass));
  142. for (var type in victims) {
  143. if (victims.hasOwnProperty(type)) {
  144. for (var key in victims[type]){
  145. if (victims[type].hasOwnProperty(key)) {
  146. if (document.getElementById("stats-" + type + "-" + key) == null) {
  147. if (victims[type][key] == 0)
  148. continue;
  149. child = document.createElement('div');
  150. child.id = "stats-" + type + "-" + key;
  151. child.classList.add("stat-line");
  152. document.getElementById("stats-" + type).appendChild(child);
  153. }
  154. document.getElementById("stats-" + type + "-" + key).innerHTML = key + ": " + victims[type][key];
  155. }
  156. }
  157. }
  158. }
  159. }
  160. function pick_move()
  161. {
  162. if (!strolling) {
  163. setTimeout(pick_move, 1500 * Math.sqrt(scale));
  164. return;
  165. }
  166. var choice = Math.random();
  167. if (choice < 0.2) {
  168. anal_vore();
  169. } else if (choice < 0.6) {
  170. stomp();
  171. } else {
  172. feed();
  173. }
  174. setTimeout(pick_move, 1500 * Math.sqrt(scale));
  175. }
  176. function grow()
  177. {
  178. scale *= 1.2;
  179. update();
  180. }
  181. // pop the list and digest that object
  182. function doDigest(containerName)
  183. {
  184. var digestType = containerName == "stomach" ? stomach : bowels;
  185. var count = 0
  186. if (containerName == "stomach") {
  187. count = stomach.length;
  188. count = Math.min(count,maxStomachDigest);
  189. } else if (containerName == "bowels") {
  190. count = bowels.length;
  191. count = Math.min(count,maxBowelsDigest);
  192. }
  193. var container = new Container();
  194. while (count > 0) {
  195. --count;
  196. var toDigest = digestType.shift();
  197. if (toDigest.name != "Container")
  198. toDigest = new Container([toDigest]);
  199. container = container.merge(toDigest);
  200. }
  201. var digested = container.sum();
  202. for (var key in victims[containerName]) {
  203. if (victims[containerName].hasOwnProperty(key) && digested.hasOwnProperty(key) ) {
  204. victims["digested"][key] += digested[key];
  205. victims[containerName][key] -= digested[key];
  206. }
  207. }
  208. if (containerName == "stomach")
  209. update(["Your stomach gurgles as it digests " + container.describe(false) + " " + summarize(container.sum())]);
  210. else if (containerName == "bowels")
  211. update(["Your bowels churn as they absorb " + container.describe(false) + " " + summarize(container.sum())]);
  212. if (digestType.length > 0) {
  213. setTimeout(function() {
  214. doDigest(containerName);
  215. }, 15000);
  216. }
  217. }
  218. window.addEventListener('load', function(event) {
  219. victims["stomped"] = initVictims();
  220. victims["digested"] = initVictims();
  221. victims["stomach"] = initVictims();
  222. victims["bowels"] = initVictims();
  223. document.getElementById("button-grow").addEventListener("click",grow);
  224. document.getElementById("button-feed").addEventListener("click",feed);
  225. document.getElementById("button-stomp").addEventListener("click",stomp);
  226. document.getElementById("button-anal_vore").addEventListener("click",anal_vore);
  227. document.getElementById("button-stroll").addEventListener("click",toggle_auto);
  228. document.getElementById("button-units").addEventListener("click",toggle_units);
  229. setTimeout(pick_move, 2000);
  230. update();
  231. });