big steppy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

305 lines
6.6 KiB

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