diff options
author | Fbenas <philbeansburton@gmail.com> | 2020-10-13 20:01:41 +0100 |
---|---|---|
committer | Fbenas <philbeansburton@gmail.com> | 2020-10-13 20:01:41 +0100 |
commit | 56f42daf6aadb940c55d46b612c46f9afc3211fa (patch) | |
tree | 338ee87022e806eb21b2c49fb2dcefd48ff75178 /public/js/app.js | |
parent | 1df97b3b9d589954d23a02fc2ca2cb5d87133e26 (diff) |
Refactor components in scene to be called boids
Diffstat (limited to 'public/js/app.js')
-rw-r--r-- | public/js/app.js | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/public/js/app.js b/public/js/app.js index 53581b3..093d6df 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -230,24 +230,24 @@ class Scene { // no of boids // scene width // scene height - constructor(component_size, no_of_components) { - this.component_size = component_size; - this.no_of_components = no_of_components; - this.components = []; + constructor(boid_radius, no_of_boids) { + this.boid_radius = boid_radius; + this.no_of_boids = no_of_boids; + this.boids = []; this.gameArea = {}; this.started = false; this.width = 600; this.height = 600; this.initGameArea(); - this.initComponents(); + this.initBoids(); } - initComponents() { - let components = []; - for (let i = 0; i < this.no_of_components; i++) { - components.push(new Boid( - this.component_size, + initBoids() { + let boids = []; + for (let i = 0; i < this.no_of_boids; i++) { + boids.push(new Boid( + this.boid_radius, "black", 300, 300, Math.random() * 360, // Math.random() * (this.gameArea.canvas.width - 100) + 50, @@ -259,7 +259,7 @@ class Scene { )); } - this.components = components; + this.boids = boids; } initGameArea() { @@ -282,9 +282,9 @@ class Scene { update() { this.gameArea.clear(); - for (let i = 0; i < this.no_of_components; i++) { - this.components[i].move(this.components); - this.components[i].draw(this.gameArea.context); + for (let i = 0; i < this.no_of_boids; i++) { + this.boids[i].move(this.boids); + this.boids[i].draw(this.gameArea.context); } } @@ -302,8 +302,8 @@ class Scene { if (this.started) { this.stop(); } - this.components = new Array; - this.initComponents(); + this.boids = new Array; + this.initBoids(); this.gameArea.clear(); this.started = false; } |