var noise = require('./perlin.js'); const util = require("./util.js") function generateWorld(gridSize, perlinScale){ let x, y = 0 let tempWorld = Array.from(Array(gridSize[0]), () => new Array(gridSize[1])); for (x = 0; x < gridSize[0]; x++){ for (y = 0; y < gridSize[1]; y++){ tempWorld[x][y] = {type: 0, structure: 0, color: null, owner: null} } } noise.seed(Math.random()) for(x = 0; x < gridSize[0]; x++){ for(y = 0; y < gridSize[1]; y++){ var value = (noise.perlin2(x/perlinScale, y/perlinScale))*10; if (value >= -3) { tempWorld[x][y].type = 0 } else if (value < -3) { tempWorld[x][y].type = 1 } if (value > 1.4) { tempWorld[x][y].type = 2 } } } for (i = 0; i < gridSize[0]*gridSize[1]/15; i){ x = util.randomNumber(0,gridSize[0]); y = util.randomNumber(0,gridSize[1]); if (tempWorld[x][y].type != 1) { i++; tempWorld[x][y].structure = util.randomNumber(1,4) } } return tempWorld; } module.exports = { generateWorld };