From 224ab1728c12bbf605f76b413666009d7df3ab68 Mon Sep 17 00:00:00 2001 From: M4YX0R Date: Sat, 11 Dec 2021 11:29:56 +0300 Subject: [PATCH] Wall gen screen w/h ratio and clearWalls null fix --- src/Controllers/EnvironmentController.js | 7 +++++-- src/Environments/WorldEnvironment.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Controllers/EnvironmentController.js b/src/Controllers/EnvironmentController.js index bb19cc9..7f96b00 100644 --- a/src/Controllers/EnvironmentController.js +++ b/src/Controllers/EnvironmentController.js @@ -59,13 +59,16 @@ class EnvironmentController extends CanvasController{ this.env.clearWalls(); var noise_threshold = -0.017; var avg_noise = 0; + var resolution = 20; Perlin.seed(); for (var r = 0; r < this.env.num_rows; r++) { for (var c = 0; c < this.env.num_cols; c++) { - var noise = Perlin.get(c/this.env.num_cols*(20/this.env.renderer.cell_size), r/this.env.num_rows*(20/this.env.renderer.cell_size)); + var xval = c/this.env.num_cols*(resolution/this.env.renderer.cell_size*(this.env.num_cols/this.env.num_rows)); + var yval = r/this.env.num_rows*(resolution/this.env.renderer.cell_size*(this.env.num_rows/this.env.num_cols)); + var noise = Perlin.get(xval, yval); avg_noise += noise/(this.env.num_rows*this.env.num_cols); - if (noise > noise_threshold && noise < noise_threshold + thickness/(4*this.env.renderer.cell_size)) { + if (noise > noise_threshold && noise < noise_threshold + thickness/100*this.env.renderer.cell_size) { var cell = this.env.grid_map.cellAt(c, r); if (cell != null) { if(cell.owner != null) cell.owner.die(); diff --git a/src/Environments/WorldEnvironment.js b/src/Environments/WorldEnvironment.js index 3db4c31..791fc66 100644 --- a/src/Environments/WorldEnvironment.js +++ b/src/Environments/WorldEnvironment.js @@ -104,7 +104,8 @@ class WorldEnvironment extends Environment{ clearWalls() { for(var wall of this.walls){ - if (this.grid_map.cellAt(wall.col, wall.row).state == CellStates.wall) + var wcell = this.grid_map.cellAt(wall.col, wall.row); + if (wcell && wcell.state == CellStates.wall) this.changeCell(wall.col, wall.row, CellStates.empty, null); } }