xxxxxxxxxx
37
/*
A school class which generates 9 fish, with a specific color and a specific starting location, in each school
*/
class School {
// Constructor function for a new School.
// Requires x, y position where the school of fish is to be created.
constructor( x, y, indice ){
// Record the x and y position inside 'this'
this.x = x;
this.y = y;
this.indice = indice ;
this.sCol = color( random(256), random(256), random(256) ) ;
}
// Function to generate the fish of this school.
// Create 9 fish.
generateFish() {
fishes[ this.indice ] = [] ;
for( let i = this.indice; i < this.indice + 9; i++ ) {
let xPos = this.x + (i*10) ;
fishes[ this.indice ].push(new Fish(xPos, this.y, this.sCol));
}
}
show() {
// Loop over the array and update each fish.
for (let f of fishes[this.indice]){
f.update();
f.show();
}
}
}