diff options
author | Fbenas <philbeansburton@gmail.com> | 2020-09-23 19:21:31 +0100 |
---|---|---|
committer | Fbenas <philbeansburton@gmail.com> | 2020-09-23 19:21:31 +0100 |
commit | 0b89973e8e1b2251545def7796c246d68ad8e061 (patch) | |
tree | e57ff6f96f2f4a1b7c2223575b25ec4a19a20484 /resources/js/scene.js | |
parent | 5c4f8661dbbc54f607bdac4676a74995463cdece (diff) |
Add simple ray-traced collision detection
Diffstat (limited to 'resources/js/scene.js')
-rw-r--r-- | resources/js/scene.js | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/resources/js/scene.js b/resources/js/scene.js index 684cd11..7e7e895 100644 --- a/resources/js/scene.js +++ b/resources/js/scene.js @@ -3,7 +3,7 @@ class Scene { constructor(component_size, no_of_components) { this.component_size = component_size; this.no_of_components = no_of_components; - this.components = new Array; + this.components = []; this.gameArea = {}; this.initGameArea(); this.initComponents(); @@ -11,17 +11,32 @@ class Scene { } initComponents() { + let components = []; for (let i = 0; i < this.no_of_components; i++) { - let new_component = new Component( + let x, y, z; + if (i == 0) { + x = 100; + y = 100; + z = 0; + } else { + x = 105; + y = 100; + z = 180; + } + + components.push(new Component( + this.gameArea.context, this.component_size, "black", - Math.random() * this.gameArea.canvas.width, - Math.random() * this.gameArea.canvas.height, - Math.random() * 360 - // 18, 100, 180 - ); - this.components.push(new_component); + // x, y, z, + Math.random() * (this.gameArea.canvas.width - 100) + 50, + Math.random() * (this.gameArea.canvas.height - 100) + 50, + Math.random() * 360, + i + )); } + + this.components = components; } initGameArea() { @@ -45,7 +60,7 @@ class Scene { update() { this.gameArea.clear(); for (let i = 0; i < this.no_of_components; i++) { - this.components[i].move(this.gameArea.context); + this.components[i].move(this.gameArea.context, this.components); } } |