2022-06-19 20:21:33 +00:00
|
|
|
const util = require("./util.js")
|
2022-06-21 14:46:34 +00:00
|
|
|
const log = require("./log.js")
|
2022-06-19 20:21:33 +00:00
|
|
|
|
|
|
|
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++){
|
2022-06-21 14:46:34 +00:00
|
|
|
tempWorld[x][y] = {type: 0, structure: 0}
|
2022-06-19 20:21:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(x = 0; x < gridSize[0]; x++){
|
|
|
|
for(y = 0; y < gridSize[1]; y++){
|
2022-06-21 14:46:34 +00:00
|
|
|
const value = util.randomNumber(0, 3);
|
|
|
|
var n;
|
|
|
|
switch (value) {
|
|
|
|
case 1:
|
|
|
|
n = 0
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
n = 6
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
n = 0
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log.log("OTHER")
|
|
|
|
n = 7
|
2022-06-19 20:21:33 +00:00
|
|
|
|
|
|
|
}
|
2022-06-21 14:46:34 +00:00
|
|
|
tempWorld[x][y].type = n
|
2022-06-19 20:21:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 14:46:34 +00:00
|
|
|
|
2022-06-19 20:21:33 +00:00
|
|
|
return tempWorld;
|
|
|
|
}
|
2022-06-21 14:46:34 +00:00
|
|
|
|
2022-06-19 20:21:33 +00:00
|
|
|
module.exports = { generateWorld };
|