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.
 
 
 

267 lines
5.8 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. };
  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 (stomachDigesting == 0)
  84. setTimeout(function() { doDigest("stomach"); }, 15000);
  85. ++stomachDigesting;
  86. updateVictims("stomach",prey);
  87. update([line]);
  88. }
  89. function stomp()
  90. {
  91. var prey = getPrey("suburb", 1.5*scale*scale);
  92. var line = prey.stomp() + " " + summarize(prey.sum());
  93. var preyMass = prey.sum_property("mass");
  94. scale = scaleAddMass(scale, baseMass, preyMass);
  95. updateVictims("stomped",prey);
  96. update([line]);
  97. }
  98. function anal_vore()
  99. {
  100. var prey = getOnePrey(scale*scale*2)
  101. var line = prey.anal_vore() + " " + summarize(prey.sum());
  102. var preyMass = prey.sum_property("mass");
  103. scale = scaleAddMass(scale, baseMass, preyMass);
  104. bowels.push(prey);
  105. if (bowelsDigesting == 0)
  106. setTimeout(function() { doDigest("bowels"); }, 15000);
  107. ++bowelsDigesting;
  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 = stomachDigesting;
  172. stomachDigesting = 0;
  173. } else if (containerName == "bowels") {
  174. count = bowelsDigesting;
  175. bowelsDigesting = 0;
  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["stomach"][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. }
  197. window.addEventListener('load', function(event) {
  198. victims["stomped"] = initVictims();
  199. victims["digested"] = initVictims();
  200. victims["stomach"] = initVictims();
  201. victims["bowels"] = initVictims();
  202. document.getElementById("button-grow").addEventListener("click",grow);
  203. document.getElementById("button-feed").addEventListener("click",feed);
  204. document.getElementById("button-stomp").addEventListener("click",stomp);
  205. document.getElementById("button-anal_vore").addEventListener("click",anal_vore);
  206. document.getElementById("button-stroll").addEventListener("click",toggle_auto);
  207. setTimeout(pick_move, 2000);
  208. update();
  209. });