From 50d25f3103d3a1e7e37e2fe02d3ee723d6370401 Mon Sep 17 00:00:00 2001 From: klangner Date: Sat, 17 Oct 2020 22:11:21 +0200 Subject: [PATCH] better walls --- demo/www/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/demo/www/index.js b/demo/www/index.js index cecb27f..532e4f4 100644 --- a/demo/www/index.js +++ b/demo/www/index.js @@ -93,10 +93,14 @@ const getIndex = (row, column) => { }; const is_inner_wall = (tiles, col, row) => { - if (col > 0 && tiles[getIndex(row, col-1)] == Cell.Floor) {return false} - if (row > 0 && tiles[getIndex(row-1, col)] == Cell.Floor) {return false} - if (col < width-1 && tiles[getIndex(row, col+1)] == Cell.Floor) {return false} - if (row < height-1 && tiles[getIndex(row+1, col)] == Cell.Floor) {return false} + + for (let c = Math.max(col-1, 0); c < Math.min(col+2, width); c++) { + for (let r = Math.max(row-1, 0); r < Math.min(row+2, height); r++) { + if ((c != col || r != row) && tiles[getIndex(r, c)] == Cell.Floor) { + return false; + } + } + } return true; }