Procházet zdrojové kódy

more ass

tags/v0.7.0
Fen Dweller před 8 roky
rodič
revize
6fa333f3bb
3 změnil soubory, kde provedl 144 přidání a 24 odebrání
  1. +56
    -20
      game.js
  2. +84
    -2
      recursive-macro.js
  3. +4
    -2
      stroll.html

+ 56
- 20
game.js Zobrazit soubor

@@ -2,8 +2,41 @@ var baseHeight = 3.65;
var baseMass = 1360; var baseMass = 1360;
var scale = 1; var scale = 1;


var people = 0;
var cars = 0;
var victims =
{
"Person": 0,
"Car": 0,
"Bus": 0,
"Motorcycle": 0,
"House": 0,
"Train": 0,
"Parking Garage": 0,
"Overpass": 0
}

function getPrey(region, area)
{
switch(region)
{
case "suburb": return suburbPrey(area);
}
}

function suburbPrey(area)
{
return fill_area(area, {"Person": 0.5, "House": 0.5, "Car": 0.2});
}

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

for (var key in sums) {
if (sums.hasOwnProperty(key)) {
victims[key] += sums[key];
}
}
}


function scaleAddMass(scale, baseMass, mass) function scaleAddMass(scale, baseMass, mass)
{ {
@@ -17,20 +50,19 @@ function feed()
var log = document.getElementById("log"); var log = document.getElementById("log");
var line = document.createElement('div'); var line = document.createElement('div');


var prey = new Person(Math.round(scale * scale * (Math.random() / 5 + 1)));

people += prey.count;
var prey = getPrey("suburb", 2*scale*scale);
updateVictims(prey);


line.innerHTML = prey.eat(); line.innerHTML = prey.eat();
log.appendChild(line); log.appendChild(line);


var preyMass = prey.sum_property("mass");
var preyMass = prey.sum_property("mass") * 3;


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


update(); update();


setTimeout(feed, 2500);
setTimeout(feed, 2000);
} }


function stomp() function stomp()
@@ -38,20 +70,19 @@ function stomp()
var log = document.getElementById("log"); var log = document.getElementById("log");
var line = document.createElement('div'); var line = document.createElement('div');


var prey = new Person(Math.round(scale * scale * (Math.random() / 4 + 1)));

people += prey.count;
var prey = getPrey("suburb", 2*scale*scale);
updateVictims(prey);


line.innerHTML = prey.stomp(); line.innerHTML = prey.stomp();
log.appendChild(line); log.appendChild(line);


var preyMass = prey.sum_property("mass")/3;
var preyMass = prey.sum_property("mass");


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


update(); update();


setTimeout(stomp, 1500);
setTimeout(stomp, 1250);
} }


function anal_vore() function anal_vore()
@@ -59,14 +90,15 @@ function anal_vore()
var log = document.getElementById("log"); var log = document.getElementById("log");
var line = document.createElement('div'); var line = document.createElement('div');


var prey = new Person(Math.round(scale * scale * 3 * (Math.random() / 3 + 1)));

people += prey.count;
var prey = getPrey("suburb", 4*scale*scale);
if (prey.name == "Person" && prey.count == 1 && scale*scale > 4)
prey = new Car(1);
updateVictims(prey);


line.innerHTML = prey.anal_vore(); line.innerHTML = prey.anal_vore();
log.appendChild(line); log.appendChild(line);


var preyMass = prey.sum_property("mass");
var preyMass = prey.sum_property("mass") * 5;


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


@@ -86,13 +118,17 @@ function update()
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";


document.getElementById("people").innerHTML = "People: " + people;
document.getElementById("cars").innerHTML = "Cars: " + cars;
for (var key in victims){
if (victims.hasOwnProperty(key)) {
if (victims[key] > 0)
document.getElementById(key).innerHTML = key + ": " + victims[key];
}
}
} }


window.addEventListener('load', function(event) { window.addEventListener('load', function(event) {
setTimeout(feed, 2500);
setTimeout(stomp, 1500);
setTimeout(feed, 2000);
setTimeout(stomp, 1250);
setTimeout(anal_vore, 4500); setTimeout(anal_vore, 4500);


update(); update();


+ 84
- 2
recursive-macro.js Zobrazit soubor

@@ -1,6 +1,21 @@


var things =
{
"Container": Container,
"Person": Person,
"Empty Car": EmptyCar,
"Car": Car,
"Bus": Bus,
"Motorcycle": Motorcycle,
"House": House,
"Train": Train,
"Parking Garage": ParkingGarage,
"Overpass": Overpass
};

var areas = var areas =
{ {
"Container": 0,
"Person": 1, "Person": 1,
"Car": 4, "Car": 4,
"Bus": 12, "Bus": 12,
@@ -11,8 +26,48 @@ var areas =
"Overpass": 10000 "Overpass": 10000
}; };


function fill_area(area, weights = {"Person": 0.1})
{
var testRadius = Math.sqrt(area / Math.PI);
result = []
for (var key in weights) {
if (weights.hasOwnProperty(key)) {
var objArea = areas[key];
var objRadius = Math.sqrt(objArea / Math.PI);
var newRadius = testRadius - objRadius;

if (newRadius > 0) {
var newArea = newRadius * newRadius * Math.PI;
var numObjs = weights[key] * newArea;
if (numObjs < 1) {
numObjs = Math.random() > numObjs ? 0 : 1;
}
else {
numObjs = Math.round(numObjs);
}

if (numObjs > 0)
result.push(new things[key](numObjs));
else {
// try again with a better chance for just one
}

}

}
}

if (result.length > 1)
return new Container(result);
else if (result.length == 1)
return result[0];
else
return new Person();
}

var masses = var masses =
{ {
"Container": 0,
"Person": 80, "Person": 80,
"Car": 1000, "Car": 1000,
"Bus": 5000, "Bus": 5000,
@@ -26,7 +81,7 @@ var masses =
// describes everything in the container // describes everything in the container


function describe_all(contents) { function describe_all(contents) {
things = [];
var things = [];
for (var key in contents) { for (var key in contents) {
if (contents.hasOwnProperty(key)) { if (contents.hasOwnProperty(key)) {
things.push(contents[key].describe()); things.push(contents[key].describe());
@@ -125,7 +180,8 @@ function defaultSum(thing) {
return function() { return function() {
var counts = {} var counts = {}


counts[thing.name] = thing.count;
if (thing.name != "Container")
counts[thing.name] = thing.count;


for (var key in thing.contents) { for (var key in thing.contents) {
if (thing.contents.hasOwnProperty(key)) { if (thing.contents.hasOwnProperty(key)) {
@@ -181,6 +237,32 @@ function copy_defaults(self,proto) {
} }
} }


function Container(contents = []) {
this.name = "Container";

copy_defaults(this,new DefaultEntity());

this.count = 0;

this.contents = {}

for (var i=0; i < contents.length; i++) {
this.contents[contents[i].name] = contents[i];
}

for (var key in this.contents) {
if (this.contents.hasOwnProperty(key)) {
this.count += this.contents[key].count;
}
}

this.describe = function() {
return describe_all(this.contents)
}

return this;
}

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




+ 4
- 2
stroll.html Zobrazit soubor

@@ -13,7 +13,9 @@
</div> </div>
<div id=height></div> <div id=height></div>
<div id=mass></div> <div id=mass></div>
<div id=people></div>
<div id=cars></div>
<div id=Person></div>
<div id=Car></div>
<div id=Bus></div>
<div id=House></div>
</body> </body>
</html> </html>

Načítá se…
Zrušit
Uložit