Переглянути джерело

Added counters, some stomach/bowel logic, digestion action, and fixes for the trains. Also added buttons to make moves and an auto-walk button

tags/v0.7.0
Fen Dweller 8 роки тому
джерело
коміт
5c709a4d2f
4 змінених файлів з 175 додано та 56 видалено
  1. +114
    -40
      game.js
  2. +24
    -8
      recursive-macro.js
  3. +26
    -8
      stroll.html
  4. +11
    -0
      style.css

+ 114
- 40
game.js Переглянути файл

@@ -2,17 +2,27 @@ var baseHeight = 3.65;
var baseMass = 1360; var baseMass = 1360;
var scale = 1; 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) function getOnePrey(area)
{ {
@@ -50,13 +60,13 @@ function suburbPrey(area)
return fill_area(area, {"Person": 0.5, "House": 0.5, "Car": 0.2}); return fill_area(area, {"Person": 0.5, "House": 0.5, "Car": 0.2});
} }


function updateVictims(prey)
function updateVictims(type,prey)
{ {
var sums = prey.sum(); var sums = prey.sum();


for (var key in sums) { for (var key in sums) {
if (sums.hasOwnProperty(key)) { if (sums.hasOwnProperty(key)) {
victims[key] += sums[key];
victims[type][key] += sums[key];
} }
} }
} }
@@ -70,95 +80,159 @@ function scaleAddMass(scale, baseMass, mass)


function feed() function feed()
{ {
var log = document.getElementById("log");
var line = document.createElement('div');

var prey = getPrey("suburb", 0.5*scale*scale); 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"); var preyMass = prey.sum_property("mass");


scale = scaleAddMass(scale, baseMass, preyMass); scale = scaleAddMass(scale, baseMass, preyMass);


update();
updateVictims("stomach",prey);
update([line]);
} }


function stomp() function stomp()
{ {
var log = document.getElementById("log");
var line = document.createElement('div');

var prey = getPrey("suburb", 1.5*scale*scale); 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"); var preyMass = prey.sum_property("mass");


scale = scaleAddMass(scale, baseMass, preyMass); scale = scaleAddMass(scale, baseMass, preyMass);


update();
updateVictims("stomped",prey);
update([line]);

} }


function anal_vore() function anal_vore()
{ {
var log = document.getElementById("log");
var line = document.createElement('div');

var prey = getOnePrey(scale*scale*2) 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"); var preyMass = prey.sum_property("mass");


scale = scaleAddMass(scale, baseMass, preyMass); scale = scaleAddMass(scale, baseMass, preyMass);


update();
updateVictims("bowels",prey);
update([line]);
} }


function update()
function update(lines = [])
{ {
var log = document.getElementById("log"); var log = document.getElementById("log");


lines.forEach(function (x) {
var line = document.createElement('div');
line.innerHTML = x;
log.appendChild(line);
});

log.scrollTop = log.scrollHeight; log.scrollTop = log.scrollHeight;

var height = baseHeight * scale; var height = baseHeight * scale;
var mass = baseMass * Math.pow(scale, 3); var mass = baseMass * Math.pow(scale, 3);


document.getElementById("height").innerHTML = "Height: " + Math.round(height * 3) + " feet"; document.getElementById("height").innerHTML = "Height: " + Math.round(height * 3) + " feet";
document.getElementById("mass").innerHTML = "Mass: " + Math.round(mass * 2.2) + " pounds"; 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() function pick_move()
{ {
if (!strolling) {
setTimeout(pick_move, 2000);
return;
}
var choice = Math.random(); var choice = Math.random();


if (choice < 0.2) { if (choice < 0.2) {
anal_vore(); anal_vore();
setTimeout(pick_move, 4000);
setTimeout(pick_move, 2000);
} else if (choice < 0.6) { } else if (choice < 0.6) {
stomp(); stomp();
setTimeout(pick_move, 1500);
setTimeout(pick_move, 2000);
} else { } else {
feed(); feed();
setTimeout(pick_move, 2000); 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) { window.addEventListener('load', function(event) {
victims["stomped"] = initVictims();
victims["digested"] = initVictims();
victims["stomach"] = initVictims();
victims["bowels"] = initVictims();

setTimeout(pick_move, 2000); setTimeout(pick_move, 2000);
setTimeout(digest, 5000);


update(); update();
}); });

+ 24
- 8
recursive-macro.js Переглянути файл

@@ -331,9 +331,6 @@ function Car(count = 1) {
this.count = count; this.count = count;
this.contents = {}; this.contents = {};





var amount = distribution(2,5,count); var amount = distribution(2,5,count);
this.contents.person = new Person(amount); this.contents.person = new Person(amount);


@@ -364,13 +361,11 @@ function Bus(count = 1) {
this.count = count; this.count = count;
this.contents = {}; this.contents = {};





var amount = distribution(10,35,count); var amount = distribution(10,35,count);
this.contents.person = new Person(amount); this.contents.person = new Person(amount);


this.describeOne = function(verbose=true) { this.describeOne = function(verbose=true) {
adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
color = random_desc(["black","tan","gray"], (verbose ? 1 : 0)); color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
type = random_desc(["bus","double-decker bus","articulating bus"]); type = random_desc(["bus","double-decker bus","articulating bus"]);
return "a " + merge_desc([adjective,color,type]); return "a " + merge_desc([adjective,color,type]);
@@ -406,14 +401,35 @@ function Motorcycle(count = 1) {
function Train(count = 1) { function Train(count = 1) {
this.name = "Train"; this.name = "Train";
copy_defaults(this,new DefaultEntity()); copy_defaults(this,new DefaultEntity());

this.count = count; this.count = count;
this.contents = {}; 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) { function House(count = 1) {


+ 26
- 8
stroll.html Переглянути файл

@@ -8,14 +8,32 @@
<script src="game.js"></script> <script src="game.js"></script>
</head> </head>
<body> <body>
<div id=log>
It's a nice day for a walk.
<div id=game-area>
<div id=log>
It's a nice day for a walk.
</div>
<button onclick="grow()">Get Bigger</button>
<button onclick="feed()">Eat</button>
<button onclick="stomp()">Stomp</button>
<button onclick="anal_vore()">Sit</button>
<div></div>
<button onclick="toggle_auto()">Stroll</button>
<p>Stats</p>
<div id=height></div>
<div id=mass></div>
<div class=stat-header id=stats-stomped>
<p>Stomped</p>
</div>
<div class=stat-header id=stats-digested>
<p>Digested</p>
</div>
<div class=stat-header id=stats-stomach>
<p>Stomach</p>
</div>
<div class=stat-header id=stats-bowels>
<p>Bowels</p>
</div>
</div> </div>
<div id=height></div>
<div id=mass></div>
<div id=Person></div>
<div id=Car></div>
<div id=Bus></div>
<div id=House></div>
</body> </body>
</html> </html>

+ 11
- 0
style.css Переглянути файл

@@ -3,4 +3,15 @@
width:600px; width:600px;
border:1px solid #ccc; border:1px solid #ccc;
overflow:auto; overflow:auto;
float:left;
}

.stat-header {
font-weight: bold;
font-size: 150%;
}

.stat-line {
font-weight: normal;
font-size: 12pt;
} }

Завантаження…
Відмінити
Зберегти