ソースを参照

More layout improvements. Choosable locations with rural/suburb/city/downtown possibilities. Added cows and barns. Adjusted areas. Improved area filler

tags/v0.7.0
Fen Dweller 7年前
コミット
605b5d725d
4個のファイルの変更201行の追加48行の削除
  1. +105
    -22
      game.js
  2. +78
    -4
      recursive-macro.js
  3. +5
    -9
      stroll.html
  4. +13
    -13
      units.js

+ 105
- 22
game.js ファイルの表示

@@ -11,25 +11,51 @@ var metric = true;


var verbose = true; var verbose = true;


var biome = "suburb";

var newline = " "; var newline = " ";


victims = {}; victims = {};


function get_living_prey(sum) {
var total = 0;
for (var key in sum) {
if (sum.hasOwnProperty(key)) {
if (key == "Person" || key == "Cow")
total += sum[key];
}
}

return total;
}

function toggle_auto() function toggle_auto()
{ {
strolling = !strolling; strolling = !strolling;
document.getElementById("strolling-indicator").innerHTML = strolling ? "Strolling" : "Standing";
document.getElementById("button-stroll").innerHTML = "Status: " + (strolling ? "Strolling" : "Standing");
if (strolling) if (strolling)
update(["You start walking."]);
update(["You start walking.",newline]);
else else
update(["You stop walking."]);
update(["You stop walking.",newline]);
}

function change_location()
{
switch(biome) {
case "suburb": biome = "city"; break;
case "city": biome = "downtown"; break;
case "downtown": biome = "rural"; break;
case "rural": biome = "suburb"; break;
}

document.getElementById("button-location").innerHTML = "Location: " + biome.charAt(0).toUpperCase() + biome.slice(1);
} }


function toggle_units() function toggle_units()
{ {
metric = !metric; metric = !metric;


document.getElementById("button-units").innerHTML = metric ? "Metric" : "Customary";
document.getElementById("button-units").innerHTML = "Units: " + (metric ? "Metric" : "Customary");


update(); update();
} }
@@ -38,18 +64,20 @@ function toggle_verbose()
{ {
verbose = !verbose; verbose = !verbose;


document.getElementById("button-verbose").innerHTML = verbose ? "Verbose" : "Simple";
document.getElementById("button-verbose").innerHTML = "Descriptions: " + (verbose ? "Verbose" : "Simple");
} }


function initVictims() function initVictims()
{ {
return { return {
"Person": 0, "Person": 0,
"Cow": 0,
"Car": 0, "Car": 0,
"Bus": 0, "Bus": 0,
"Tram": 0, "Tram": 0,
"Motorcycle": 0, "Motorcycle": 0,
"House": 0, "House": 0,
"Barn": 0,
"Small Skyscraper": 0, "Small Skyscraper": 0,
"Train": 0, "Train": 0,
"Train Car": 0, "Train Car": 0,
@@ -61,15 +89,23 @@ function initVictims()
// lists out total people // lists out total people
function summarize(sum, fatal = true) function summarize(sum, fatal = true)
{ {
return "<b>(" + sum["Person"] + " " + (fatal ? (sum["Person"] > 1 ? "kills" : "kill") : (sum["Person"] > 1 ? "people" : "person")) + ")</b>";
var count = get_living_prey(sum);
return "<b>(" + count + " " + (fatal ? (count > 1 ? "kills" : "kill") : (count > 1 ? "prey" : "prey")) + ")</b>";
} }


var stomach = [] var stomach = []
var bowels = [] var bowels = []


function getOnePrey(area)
function getOnePrey(biome,area)
{ {
var potential = ["Person", "Car", "Bus", "Tram", "House", "Train", "Parking Garage", "Small Skyscraper"];
var potential = ["Person"];

switch(biome) {
case "suburb": potential = ["Person", "Car", "Bus", "Train", "House"]; break;
case "city": potential = ["Person", "Car", "Bus", "Train", "Tram", "House", "Parking Garage"]; break;
case "downtown": potential = ["Person", "Car", "Bus", "Tram", "Small Skyscraper", "Parking Garage"]; break;
case "rural": potential = ["Person", "Barn", "House", "Cow"]; break;
}


var potAreas = [] var potAreas = []


@@ -92,16 +128,44 @@ function getOnePrey(area)
} }
function getPrey(region, area) function getPrey(region, area)
{ {
var weights = {"Person": 1};

switch(region) switch(region)
{ {
case "suburb": return suburbPrey(area);
case "rural": weights = {
"Person": 0.05,
"House": 0.01,
"Barn": 0.01,
"Cow": 0.2
}; break;
case "suburb": weights = {
"Person": 0.5,
"House": 0.5,
"Car": 0.2,
"Train": 0.1,
"Bus": 0.1
}; break;
case "city": weights = {
"Person": 0.5,
"House": 0.2,
"Car": 0.2,
"Train": 0.1,
"Bus": 0.1,
"Tram": 0.1,
"Parking Garage": 0.02
}; break;
case "downtown": weights = {
"Person": 0.5,
"Car": 0.3,
"Bus": 0.15,
"Tram": 0.1,
"Parking Garage": 0.02,
"Small Skyscraper": 0.4
}; break;
} }
return fill_area2(area,weights);
} }


function suburbPrey(area)
{
return fill_area2(area, {"Person": 0.5, "House": 0.5, "Car": 0.2, "Tram": 0.1, "Bus": 0.1, "Small Skyscraper": 0.05, "Parking Garage": 0.02, "Train": 0.05});
}


function updateVictims(type,prey) function updateVictims(type,prey)
{ {
@@ -123,12 +187,13 @@ function scaleAddMass(scale, baseMass, mass)


function feed() function feed()
{ {
var prey = getPrey("suburb", 0.5*scale*scale);
var area = baseHeight / 30 * scale * scale;
var prey = getPrey(biome, area);


var line = prey.eat(verbose) var line = prey.eat(verbose)
var linesummary = summarize(prey.sum(), false); var linesummary = summarize(prey.sum(), false);


var people = prey.sum()["Person"];
var people = get_living_prey(prey.sum());
var sound = "Ulp"; var sound = "Ulp";


if (people < 3) { if (people < 3) {
@@ -160,11 +225,12 @@ function feed()


function stomp() function stomp()
{ {
var prey = getPrey("suburb", 1.5*scale*scale);
var area = baseHeight / 15 * scale * scale;
var prey = getPrey(biome, area);
var line = prey.stomp(verbose) var line = prey.stomp(verbose)
var linesummary = summarize(prey.sum(), true); var linesummary = summarize(prey.sum(), true);


var people = prey.sum()["Person"];
var people = get_living_prey(prey.sum());


var sound = "Thump"; var sound = "Thump";


@@ -191,14 +257,17 @@ function stomp()


function anal_vore() function anal_vore()
{ {
var prey = getOnePrey(0.25*scale*scale);
var crushed = getPrey("suburb",3*scale*scale);
var area = baseHeight / 30 * scale * scale;
var prey = getOnePrey(biome,area);

area = baseHeight * scale * scale / 5;
var crushed = getPrey(biome,3*scale*scale);
var line1 = prey.anal_vore(verbose, baseHeight*scale); var line1 = prey.anal_vore(verbose, baseHeight*scale);
var line1summary = summarize(prey.sum(), false); var line1summary = summarize(prey.sum(), false);
var line2 = crushed.buttcrush(verbose); var line2 = crushed.buttcrush(verbose);
var line2summary = summarize(crushed.sum(), true); var line2summary = summarize(crushed.sum(), true);


var people = prey.sum()["Person"];
var people = get_living_prey(prey.sum());
var sound = "Shlp"; var sound = "Shlp";


if (people < 3) { if (people < 3) {
@@ -215,7 +284,7 @@ function anal_vore()
sound = "Oh the humanity!"; sound = "Oh the humanity!";
} }


people = crushed.sum()["Person"];
var people = get_living_prey(crushed.sum());
var sound2 = "Thump"; var sound2 = "Thump";


if (people < 3) { if (people < 3) {
@@ -305,8 +374,21 @@ function pick_move()


function grow() function grow()
{ {
var oldHeight = baseHeight * scale;
var oldMass = baseMass * Math.pow(scale,3);

scale *= 1.2; scale *= 1.2;
update();

var newHeight = baseHeight * scale;
var newMass = baseMass * Math.pow(scale,3);

var heightDelta = newHeight - oldHeight;
var massDelta = newMass - oldMass;

var heightStr = metric ? metricLength(heightDelta) : customaryLength(heightDelta);
var massStr = metric ? metricMass(massDelta) : customaryMass(massDelta);

update(["Power surges through you as you grow " + heightStr + " and gain " + massStr,newline]);
} }


// pop the list and digest that object // pop the list and digest that object
@@ -368,6 +450,7 @@ window.addEventListener('load', function(event) {
document.getElementById("button-stroll").addEventListener("click",toggle_auto); document.getElementById("button-stroll").addEventListener("click",toggle_auto);
document.getElementById("button-units").addEventListener("click",toggle_units); document.getElementById("button-units").addEventListener("click",toggle_units);
document.getElementById("button-verbose").addEventListener("click",toggle_verbose); document.getElementById("button-verbose").addEventListener("click",toggle_verbose);
document.getElementById("button-location").addEventListener("click",change_location);
setTimeout(pick_move, 2000); setTimeout(pick_move, 2000);


update(); update();


+ 78
- 4
recursive-macro.js ファイルの表示

@@ -2,12 +2,14 @@ var things =
{ {
"Container": Container, "Container": Container,
"Person": Person, "Person": Person,
"Cow": Cow,
"Empty Car": EmptyCar, "Empty Car": EmptyCar,
"Car": Car, "Car": Car,
"Bus": Bus, "Bus": Bus,
"Tram": Tram, "Tram": Tram,
"Motorcycle": Motorcycle, "Motorcycle": Motorcycle,
"House": House, "House": House,
"Barn": Barn,
"Small Skyscraper": SmallSkyscraper, "Small Skyscraper": SmallSkyscraper,
"Train": Train, "Train": Train,
"Train Car": TrainCar, "Train Car": TrainCar,
@@ -19,11 +21,13 @@ var areas =
{ {
"Container": 0, "Container": 0,
"Person": 1, "Person": 1,
"Cow": 2,
"Car": 4, "Car": 4,
"Bus": 12, "Bus": 12,
"Tram": 20, "Tram": 20,
"Motorcycle": 2, "Motorcycle": 2,
"House": 1000, "House": 1000,
"Barn": 750,
"Small Skyscraper": 10000, "Small Skyscraper": 10000,
"Train": 500, "Train": 500,
"TrainCar": 500, "TrainCar": 500,
@@ -35,11 +39,13 @@ var masses =
{ {
"Container": 0, "Container": 0,
"Person": 80, "Person": 80,
"Cow": 300,
"Car": 1000, "Car": 1000,
"Bus": 5000, "Bus": 5000,
"Tram": 10000, "Tram": 10000,
"Motorcycle": 200, "Motorcycle": 200,
"House": 10000, "House": 10000,
"Barn": 5000,
"Small Skyscraper": 100000, "Small Skyscraper": 100000,
"Train": 5000, "Train": 5000,
"Train Car": 5000, "Train Car": 5000,
@@ -49,7 +55,7 @@ var masses =


// general logic: each step fills in a fraction of the remaining space // general logic: each step fills in a fraction of the remaining space


function fill_area2(area, weights = {"Person": 0.1, "Car": 0.05, "House": 0.1})
function fill_area2(area, weights)
{ {
result = []; result = [];
candidates = []; candidates = [];
@@ -76,10 +82,10 @@ function fill_area2(area, weights = {"Person": 0.1, "Car": 0.05, "House": 0.1})


// for small amounts, actually do the randomness // for small amounts, actually do the randomness


// the first few ones get a better shot
// the first few ones get a much better shot
while (limit > 0) { while (limit > 0) {
if (limit <= 3) if (limit <= 3)
count += Math.random() < (1 - Math.pow((1 - candidate.weight),2)) ? 1 : 0;
count += Math.random() < (1 - Math.pow((1 - candidate.weight),limit*3)) ? 1 : 0;
else else
count += Math.random() < candidate.weight ? 1 : 0; count += Math.random() < candidate.weight ? 1 : 0;
--limit; --limit;
@@ -406,7 +412,6 @@ function Person(count = 1) {
} else { } else {
return (this.count > 1 ? this.count + " people" : "a person"); return (this.count > 1 ? this.count + " people" : "a person");
} }

} }


this.stomp = function(verbose=true) { this.stomp = function(verbose=true) {
@@ -427,6 +432,40 @@ function Person(count = 1) {
return this; return this;
} }


function Cow(count = 1) {
this.name = "Cow";

copy_defaults(this,new DefaultEntity());

this.count = count;
this.contents = {};


this.describeOne = function (verbose=true) {
body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
sex = random_desc(["male", "female"], (verbose ? 1 : 0));
return "a " + merge_desc([body,sex,"cow"]);
}

this.describe = function(verbose=true) {
if (verbose) {
if (count <= 3) {
list = [];
for (var i = 0; i < count; i++) {
list.push(this.describeOne(this.count <= 2));
}
return merge_things(list);
} else {
return this.count + " cattle"
}
} else {
return (this.count > 1 ? this.count + " cattle" : "a cow");
}
}

return this;
}

function EmptyCar(count = 1) { function EmptyCar(count = 1) {
this.name = "Car"; this.name = "Car";


@@ -694,6 +733,41 @@ function House(count = 1) {
} }
} }


function Barn(count = 1) {
this.name = "Barn";
copy_defaults(this,new DefaultEntity());
this.count = count;
this.contents = {};

var amount = distribution(0,2,count);
this.contents.person = new Person(amount);
amount = distribution(30,70,count);
this.contents.cow = new Cow(amount);

this.describeOne = function(verbose=true) {
size = random_desc(["little","big","large"], (verbose ? 0.5 : 0));
color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
name = random_desc(["barn","barn","barn","barn","barn","farmhouse"], 1);
return "a " + merge_desc([size,color,name]);
}

this.describe = function(verbose = true) {
if (verbose) {
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,verbose) + " inside";
} else {
return this.count + " barns with " + describe_all(this.contents,verbose) + " inside";
}
} else {
return (this.count > 1 ? this.count + " barns" : "a barn");
}
}
}

function SmallSkyscraper(count = 1) { function SmallSkyscraper(count = 1) {
this.name = "Small Skyscraper"; this.name = "Small Skyscraper";
copy_defaults(this,new DefaultEntity()); copy_defaults(this,new DefaultEntity());


+ 5
- 9
stroll.html ファイルの表示

@@ -32,7 +32,7 @@
</div> </div>
<div id=log-area> <div id=log-area>
<div id=log> <div id=log>
<div>Welcome to Stroll 0.1.6</div>
<div>Welcome to Stroll 0.1.7</div>
<div><a href="https://chemicalcrux.org/stroll">Changelog</a></div> <div><a href="https://chemicalcrux.org/stroll">Changelog</a></div>
<div>It's a nice day for a walk</div> <div>It's a nice day for a walk</div>
<div>&nbsp;</div> <div>&nbsp;</div>
@@ -40,18 +40,14 @@
</div> </div>
<div class=button-container> <div class=button-container>
<button class=action-button id=button-grow>Get Bigger</button> <button class=action-button id=button-grow>Get Bigger</button>
<p/>
<button class=action-button id=button-feed>Eat</button> <button class=action-button id=button-feed>Eat</button>
<p/>
<button class=action-button id=button-stomp>Stomp</button> <button class=action-button id=button-stomp>Stomp</button>
<p/>
<button class=action-button id=button-anal_vore>Sit</button> <button class=action-button id=button-anal_vore>Sit</button>
<p/> <p/>
<div></div>
<button class=action-button id=button-stroll>Stroll</button>
<div id=strolling-indicator>Standing</div>
<button class=action-button class=action-button id=button-units>Metric</button>
<button class=action-button id=button-verbose>Verbose</button>
<button class=action-button id=button-stroll>Status: Standing</button>
<button class=action-button id=button-location>Location: Suburb</button>
<button class=action-button class=action-button id=button-units>Units: Metric</button>
<button class=action-button id=button-verbose>Descriptions: Verbose</button>
</div> </div>
</div> </div>
</body> </body>


+ 13
- 13
units.js ファイルの表示

@@ -4,22 +4,22 @@ function round(number,precision=3) {


function metricMass(kg) { function metricMass(kg) {
if (kg < 1) { if (kg < 1) {
var mass = round(kg * 1000);
var mass = round(kg * 1000,0);
return mass + (mass == 1 ? " gram" : " grams"); return mass + (mass == 1 ? " gram" : " grams");
} else if (kg < 5000) {
} else if (kg < 5000,0) {
var mass = round(kg); var mass = round(kg);
return mass + (mass == 1 ? " kilogram" : " kilograms"); return mass + (mass == 1 ? " kilogram" : " kilograms");
} else if (kg < 5000000) { } else if (kg < 5000000) {
var mass = round(kg / 1000);
var mass = round(kg / 1000,1);
return mass + (mass == 1 ? " metric ton" : " metric tons"); return mass + (mass == 1 ? " metric ton" : " metric tons");
} else if (kg < 5000000000) { } else if (kg < 5000000000) {
var mass = round(kg / 1000000);
var mass = round(kg / 1000000,1);
return mass + (mass == 1 ? " kiloton" : " kilotons"); return mass + (mass == 1 ? " kiloton" : " kilotons");
} else if (kg < 5000000000000) { } else if (kg < 5000000000000) {
var mass = round(kg / 1000000000);
var mass = round(kg / 1000000000,1);
return mass + (mass == 1 ? " megaton" : " megatons"); return mass + (mass == 1 ? " megaton" : " megatons");
} else { } else {
var mass = round(kg / 1000000000000);
var mass = round(kg / 1000000000000,1);
return mass + (mass == 1 ? " gigaton" : " gigatons"); return mass + (mass == 1 ? " gigaton" : " gigatons");
} }
} }
@@ -28,26 +28,26 @@ function customaryMass(kg) {
var lbs = kg * 2.2; var lbs = kg * 2.2;


if (lbs < 1) { if (lbs < 1) {
var mass = round(lbs * 16);
var mass = round(lbs * 16,0);
return mass + (mass == 1 ? " ounce" : " ounces"); return mass + (mass == 1 ? " ounce" : " ounces");
} else if (lbs < 2000) { } else if (lbs < 2000) {
var mass = round(lbs);
var mass = round(lbs,0);
return mass + (mass == 1 ? " pound" : " pounds"); return mass + (mass == 1 ? " pound" : " pounds");
} else { } else {
var mass = round(lbs / 2000);
var mass = round(lbs / 2000,1);
return mass + (mass == 1 ? "ton" : " tons"); return mass + (mass == 1 ? "ton" : " tons");
} }
} }


function metricLength(m) { function metricLength(m) {
if (m < 1) { if (m < 1) {
var length = round(m * 100);
var length = round(m * 100,0);
return length + (length == 1 ? " centimeter" : " centimeters"); return length + (length == 1 ? " centimeter" : " centimeters");
} else if (m < 500) { } else if (m < 500) {
var length = round(m);
var length = round(m,2);
return length + (length == 1 ? " meter" : " meters"); return length + (length == 1 ? " meter" : " meters");
} else { } else {
var length = round(m / 1000);
var length = round(m / 1000,1);
return length + (length == 1 ? " kilometer" : " kilometers"); return length + (length == 1 ? " kilometer" : " kilometers");
} }
} }
@@ -63,7 +63,7 @@ function customaryLength(m) {
var length = Math.floor(ft); var length = Math.floor(ft);
return length + (length == 1 ? " foot" : " feet") + " " + end; return length + (length == 1 ? " foot" : " feet") + " " + end;
} else { } else {
var length = round(ft/5280);
var length = round(ft/5280,1);
return length + (length == 1 ? " mile" : " miles"); return length + (length == 1 ? " mile" : " miles");
} }
} }

読み込み中…
キャンセル
保存