big steppy
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

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