xxxxxxxxxx
86
// Constructor
class World {
constructor(num) {
this.bloops = [];
this.foods = [];
this.baseWord = baseWord;
for (let i = 0; i < num; i++) {
let l = createVector(random(width), random(height));
let fl = createVector(random(width), random(height));
let theWord = this.baseWord;
let dna = new DNA();
this.bloops.push(new Bloop(l, dna, theWord));
// this.food= name;
let randomWord= relatedWords[floor(random(relatedWords.length))].word
this.foods.push(new Food(fl, randomWord));
}
}
// Make a new creature
born(x, y, word) {
let l = createVector(x, y);
let dna = new DNA();
this.bloops.push(new Bloop(l, dna, word));
}
add(l) {
let randomWord= relatedWords[floor(random(relatedWords.length))].word
this.foods.push(new Food(fl, randomWord));
}
// Run the world
run() {
// Deal with food
// There's a small chance food will appear randomly
if (random(1) < 50*0.0005) {
let l = createVector(random(width), random(height));
let randomWord= relatedWords[floor(random(relatedWords.length))].word
this.foods.push(new Food(l, randomWord));
}
if (random(1) < 50*0.00005) {
let l = createVector(random(width), random(height));
let randomWord= wordsThatRhyme[floor(random(wordsThatRhyme.length))].word
this.foods.push(new Food(l, randomWord));
}
//display of foods
for (let i = this.foods.length - 1; i >= 0; i--){
let c = this.foods[i]
c.run();
}
let name =relatedWords[floor(random(relatedWords.length))].word;
// Cycle through the ArrayList backwards b/c we are deleting
for (let i = this.bloops.length - 1; i >= 0; i--) {
// All bloops run and eat
let b = this.bloops[i];
b.run();
b.eat(this.foods);
// If it's dead, kill it and make food
if (b.dead()) {
this.bloops.splice(i, 1);
}
// Perhaps this bloop would like to make a baby?
let child = b.reproduce();
if (child != null) this.bloops.push(child);
}
}
}