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.
 
 
 

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