Working numbering

This commit is contained in:
Alexander Bass 2022-06-21 11:32:56 -04:00
parent 004a705f90
commit 3c12e33970

View file

@ -1,30 +1,45 @@
const util = require("./util.js")
const log = require("./log.js")
const searchLoc =
[
[-1,1], [0,1], [1,1],
[-1,0], [1,0],
[-1,-1],[0,-1],[1,-1]
]
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}
tempWorld[x][y] = {type: 0, structure: 0, flag: 0, mask: true}
}
}
for(x = 0; x < gridSize[0]; x++){
for(y = 0; y < gridSize[1]; y++){
const value = util.randomNumber(0, 3);
// Generate board
for(let x = 0; x < gridSize[0]; x++){
for(let y = 0; y < gridSize[1]; y++){
const value = util.randomNumber(0, 6);
var n;
switch (value) {
case 0:
n = 0;
break;
case 1:
n = 0
break;
case 2:
n = 6
break;
case 1:
n = 0
break;
case 3:
n = 0
break;
case 4:
n = 0
break;
case 5:
n = 5
break;
default:
log.log("OTHER")
n = 7
@ -34,6 +49,27 @@ function generateWorld(gridSize, perlinScale){
}
}
// Place Numbers
for(let x = 0; x < gridSize[0]; x++){
for(let y = 0; y < gridSize[1]; y++){
if (tempWorld[x][y].type === 0) {
var counter = 0;
searchLoc.forEach(location => {
const tempx = x + location[0]
const tempy = y + location[1]
if (tempx >= 0 && tempy >= 0 && tempx < gridSize[0] && tempy < gridSize[1]) {
if (tempWorld[tempx][tempy].type === 5) {
counter++;
}
}
});
if (counter !== 0) {
tempWorld[x][y].type = 15 + counter
}
}
}
}
return tempWorld;
}