big steppy
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

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