big steppy
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

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