From 56f42daf6aadb940c55d46b612c46f9afc3211fa Mon Sep 17 00:00:00 2001 From: Fbenas Date: Tue, 13 Oct 2020 20:01:41 +0100 Subject: Refactor components in scene to be called boids --- public/js/app.js | 32 ++++++++++++++++---------------- resources/js/scene.js | 32 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 32 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; } diff --git a/resources/js/scene.js b/resources/js/scene.js index 645bb9e..df456d3 100644 --- a/resources/js/scene.js +++ b/resources/js/scene.js @@ -4,24 +4,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, @@ -33,7 +33,7 @@ class Scene { )); } - this.components = components; + this.boids = boids; } initGameArea() { @@ -56,9 +56,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); } } @@ -76,8 +76,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; } -- cgit v1.2.3