From 81caa72aed6ad8f653aabb191b099ec3d544bf2b Mon Sep 17 00:00:00 2001 From: Fbenas Date: Wed, 14 Oct 2020 00:48:34 +0100 Subject: Add future collision detection... ish --- resources/js/scene.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'resources/js/scene.js') diff --git a/resources/js/scene.js b/resources/js/scene.js index 770eb92..f8858b6 100644 --- a/resources/js/scene.js +++ b/resources/js/scene.js @@ -19,14 +19,15 @@ class Scene { 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, - Math.random() * (this.gameArea.canvas.height - 100) + 50, - Math.random() * 360, + // 300, 300, 90, + parseFloat(Number(Math.random() * (this.gameArea.canvas.width - 100) + 50).toFixed(1)), + parseFloat(Number(Math.random() * (this.gameArea.canvas.height - 100) + 50).toFixed(1)), + parseFloat(Number(Math.random() * 360).toFixed(2)), i, this.width, this.height @@ -55,11 +56,19 @@ class Scene { } update() { + if (!this.started) { + return; + } this.gameArea.clear(); - for (let i = 0; i < this.no_of_boids; i++) { - this.boids[i].move(this.boids); + for (let i = 0; i < this.boids.length; i++) { + let result = this.boids[i].move(this.boids); this.boids[i].draw(this.gameArea.context); + if (!result) { + continue; + } + } + return true; } stop() { -- cgit v1.2.3