jerome Posted March 4, 2018 Share Posted March 4, 2018 really smart Quote Link to comment Share on other sites More sharing options...
foumfo Posted March 5, 2018 Author Share Posted March 5, 2018 On 3/3/2018 at 11:40 AM, JohnK said: @foumfo at last a PG done with planes so no faces are drawn where they would be hidden, with textures too - https://www.babylonjs-playground.com/#9PP17F#9 As for performance improvements? You would need to check. So from what I understand, your way would've worked perfectly if we had an array like this for example: every array[i][j] = [1,1,0,1] instead of 1 or 0. Meaning that we don't have boxes but walls and absent walls correct? Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 5, 2018 Share Posted March 5, 2018 That should work. There are many ways to do it. Quote Link to comment Share on other sites More sharing options...
foumfo Posted March 6, 2018 Author Share Posted March 6, 2018 (edited) This is how I managed to create an array that for every block contains 4 walls or absent ones: var i = 0, j = 0; var walls = []; // Initialize the walls array for (i = 0; i < map.cells.length; i++) { walls[i] = []; for (j = 0; j < map.cells[0].length; j++) { walls[i][j] = [0,0,0,0]; } } //fill the array for (i = 0; i < map.cells.length; i++) { //left column walls[i][0][3] = 1; //right column walls[i][map.cells[0].length - 1][1] = 1; for (j = 0; j < map.cells[0].length; j++) { //bottom row if (i === 0) { walls[i][j][2] = 1; continue; } //top row else if (i === map.cells.length - 1) { walls[i][j][0] = 1; continue; } for (var dir = 0; dir <= 3; dir++) { switch(dir) { //check up case 0: if (map.cells[i + 1][j] === 0) { map.cells[i][j][0] = 1; continue; } else continue; //check right case 1: if (map.cells[i][j + 1] === 0) { map.cells[i][j][1] = 1; continue; } else continue; //check down case 2: if (map.cells[i - 1][j] === 0) { map.cells[i][j][2] = 1; continue; } else continue; //check left case 3: if (map.cells[i][j - 1] === 0) { map.cells[i][j][3] = 1; continue; } else continue; } } } } map.cells being the original double array filled with 1 & 0. I could use some help with adding the planes on the scene Edited March 6, 2018 by foumfo changed the code Quote Link to comment Share on other sites More sharing options...
foumfo Posted March 8, 2018 Author Share Posted March 8, 2018 I've done it! I've managed to create an algorithm that creates a maze with all its walls and passages GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.