From 3c12e3397008c39c9424fe2201a7836c3378ac75 Mon Sep 17 00:00:00 2001 From: Alexander Bass Date: Tue, 21 Jun 2022 11:32:56 -0400 Subject: [PATCH] Working numbering --- worldgen.js | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/worldgen.js b/worldgen.js index 3b591ba..dc3b9c0 100644 --- a/worldgen.js +++ b/worldgen.js @@ -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; }