diff --git a/game.js b/game.js index 71f3d79..0c48c12 100644 --- a/game.js +++ b/game.js @@ -2,17 +2,27 @@ var baseHeight = 3.65; var baseMass = 1360; var scale = 1; -var victims = +var strolling = false; + +victims = {}; + +function toggle_auto() { - "Person": 0, - "Car": 0, - "Bus": 0, - "Motorcycle": 0, - "House": 0, - "Train": 0, - "Parking Garage": 0, - "Overpass": 0 + strolling = !strolling; } +function initVictims() +{ + return { + "Person": 0, + "Car": 0, + "Bus": 0, + "Motorcycle": 0, + "House": 0, + "Train": 0, + "Parking Garage": 0, + "Overpass": 0 + }; +}; function getOnePrey(area) { @@ -50,13 +60,13 @@ function suburbPrey(area) return fill_area(area, {"Person": 0.5, "House": 0.5, "Car": 0.2}); } -function updateVictims(prey) +function updateVictims(type,prey) { var sums = prey.sum(); for (var key in sums) { if (sums.hasOwnProperty(key)) { - victims[key] += sums[key]; + victims[type][key] += sums[key]; } } } @@ -70,95 +80,159 @@ function scaleAddMass(scale, baseMass, mass) function feed() { - var log = document.getElementById("log"); - var line = document.createElement('div'); - var prey = getPrey("suburb", 0.5*scale*scale); - updateVictims(prey); - line.innerHTML = prey.eat(); - log.appendChild(line); + var line = prey.eat(); var preyMass = prey.sum_property("mass"); scale = scaleAddMass(scale, baseMass, preyMass); - update(); + updateVictims("stomach",prey); + update([line]); } function stomp() { - var log = document.getElementById("log"); - var line = document.createElement('div'); - var prey = getPrey("suburb", 1.5*scale*scale); - updateVictims(prey); - - line.innerHTML = prey.stomp(); - log.appendChild(line); + var line = prey.stomp(); var preyMass = prey.sum_property("mass"); scale = scaleAddMass(scale, baseMass, preyMass); - update(); + updateVictims("stomped",prey); + update([line]); + } function anal_vore() { - var log = document.getElementById("log"); - var line = document.createElement('div'); - var prey = getOnePrey(scale*scale*2) - updateVictims(prey); - line.innerHTML = prey.anal_vore(); - log.appendChild(line); + var line = prey.anal_vore(); var preyMass = prey.sum_property("mass"); scale = scaleAddMass(scale, baseMass, preyMass); - update(); + updateVictims("bowels",prey); + update([line]); } -function update() +function update(lines = []) { var log = document.getElementById("log"); + lines.forEach(function (x) { + var line = document.createElement('div'); + line.innerHTML = x; + log.appendChild(line); + }); + log.scrollTop = log.scrollHeight; + var height = baseHeight * scale; var mass = baseMass * Math.pow(scale, 3); document.getElementById("height").innerHTML = "Height: " + Math.round(height * 3) + " feet"; document.getElementById("mass").innerHTML = "Mass: " + Math.round(mass * 2.2) + " pounds"; - for (var key in victims){ - if (victims.hasOwnProperty(key)) { - if (victims[key] > 0) - document.getElementById(key).innerHTML = key + ": " + victims[key]; + for (var type in victims) { + if (victims.hasOwnProperty(type)) { + for (var key in victims[type]){ + if (victims[type].hasOwnProperty(key)) { + if (document.getElementById("stats-" + type + "-" + key) == null) { + if (victims[type][key] == 0) + continue; + child = document.createElement('div'); + child.id = "stats-" + type + "-" + key; + child.classList.add("stat-line"); + document.getElementById("stats-" + type).appendChild(child); + } + document.getElementById("stats-" + type + "-" + key).innerHTML = key + ": " + victims[type][key]; + } + } } } } function pick_move() { + if (!strolling) { + setTimeout(pick_move, 2000); + return; + } var choice = Math.random(); if (choice < 0.2) { anal_vore(); - setTimeout(pick_move, 4000); + setTimeout(pick_move, 2000); } else if (choice < 0.6) { stomp(); - setTimeout(pick_move, 1500); + setTimeout(pick_move, 2000); } else { feed(); setTimeout(pick_move, 2000); } } +function grow() +{ + scale *= 1.2; + update(); +} + +function digest() +{ + var newlyDigested = initVictims(); + + var stomach = victims["stomach"]; + + for (var key in stomach) { + if (stomach.hasOwnProperty(key)) { + var digested = Math.ceil(stomach[key] / 2); + newlyDigested[key] += digested; + victims["digested"][key] += digested; + victims["stomach"][key] -= digested; + } + } + + var bowels = victims["bowels"]; + + for (var key in bowels) { + if (bowels.hasOwnProperty(key)) { + var digested = Math.ceil(bowels[key] / 3); + newlyDigested[key] += digested; + victims["digested"][key] += digested; + victims["bowels"][key] -= digested; + } + } + + var melted = []; + for (var key in newlyDigested) { + if (newlyDigested.hasOwnProperty(key) && newlyDigested[key] > 0) { + melted.push(new things[key](newlyDigested[key])); + } + } + + var meltedTotal = new Container(melted); + + if (meltedTotal.count > 0) + update(["Your stomach gurgles as it digests " + meltedTotal.describe()]); + else + update(); + setTimeout(digest, 5000); +} + window.addEventListener('load', function(event) { + victims["stomped"] = initVictims(); + victims["digested"] = initVictims(); + victims["stomach"] = initVictims(); + victims["bowels"] = initVictims(); + setTimeout(pick_move, 2000); + setTimeout(digest, 5000); update(); }); diff --git a/recursive-macro.js b/recursive-macro.js index 8e0f490..0dfb3a1 100644 --- a/recursive-macro.js +++ b/recursive-macro.js @@ -331,9 +331,6 @@ function Car(count = 1) { this.count = count; this.contents = {}; - - - var amount = distribution(2,5,count); this.contents.person = new Person(amount); @@ -364,13 +361,11 @@ function Bus(count = 1) { this.count = count; this.contents = {}; - - - var amount = distribution(10,35,count); this.contents.person = new Person(amount); this.describeOne = function(verbose=true) { + adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0)); color = random_desc(["black","tan","gray"], (verbose ? 1 : 0)); type = random_desc(["bus","double-decker bus","articulating bus"]); return "a " + merge_desc([adjective,color,type]); @@ -406,14 +401,35 @@ function Motorcycle(count = 1) { function Train(count = 1) { this.name = "Train"; copy_defaults(this,new DefaultEntity()); + this.count = count; this.contents = {}; + var amount = distribution(50,250,count); + this.contents.person = new Person(amount); + amount = distribution(10,50,count); + this.contents.emptycar = new EmptyCar(amount); - var amount = distribution(20,60,count); - this.contents.person = new Person(amount); + this.describeOne = function(verbose=true) { + adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0)); + color = random_desc(["black","tan","gray"], (verbose ? 1 : 0)); + type = random_desc(["train","passenger train","freight train"]); + return "a " + merge_desc([adjective,color,type]); + } + + this.describe = function() { + if (this.count <= 3) { + list = []; + for (var i = 0; i < this.count; i++) { + list.push(this.describeOne(this.count < 2)); + } + return merge_things(list) + " with " + describe_all(this.contents) + " inside"; + } else { + return this.count + " trains with " + describe_all(this.contents) + " inside"; + } + } } function House(count = 1) { diff --git a/stroll.html b/stroll.html index 531ba95..47bce36 100644 --- a/stroll.html +++ b/stroll.html @@ -8,14 +8,32 @@ -
- It's a nice day for a walk. +
+
+ It's a nice day for a walk. +
+ + + + +
+ + +

Stats

+
+
+
+

Stomped

+
+
+

Digested

+
+
+

Stomach

+
+
+

Bowels

+
-
-
-
-
-
-
diff --git a/style.css b/style.css index 34955e6..d4bbb00 100644 --- a/style.css +++ b/style.css @@ -3,4 +3,15 @@ width:600px; border:1px solid #ccc; overflow:auto; + float:left; +} + +.stat-header { + font-weight: bold; + font-size: 150%; +} + +.stat-line { + font-weight: normal; + font-size: 12pt; }