diff --git a/island/data.ts b/island/data.ts new file mode 100644 index 0000000..785fae2 --- /dev/null +++ b/island/data.ts @@ -0,0 +1,8 @@ +export type TILE = number; + +export const WATER = 0; +export const BEACH = 1; +export const LIGHT_FOREST = 2; +export const DENSE_FOREST = 3; +export const MOUNTAIN = 4; +export const ICECAP = 9; diff --git a/island/grid.ts b/island/grid.ts index 89cc15e..50a5df2 100644 --- a/island/grid.ts +++ b/island/grid.ts @@ -1,4 +1,5 @@ import { Prng, mulberry32 } from "../lib/prng"; +import { BEACH, ICECAP, LIGHT_FOREST, MOUNTAIN, WATER } from "./data"; export class IslandGrid { data: number[]; @@ -99,7 +100,7 @@ export class IslandGrid { // flat, increase elevation const newValue = ++this.data[pos]; - if (newValue == 9) { + if (newValue == ICECAP) { this.done = true; } } @@ -111,28 +112,39 @@ export class IslandGrid { } public step() { - const lowlandTiles1 = this.floodSearch(this.lobePos1, (tile) => tile > 0); - const lowlandTiles2 = this.floodSearch(this.lobePos2, (tile) => tile > 0); + const lowlandTiles1 = this.floodSearch( + this.lobePos1, + (tile) => tile > WATER + ); + const lowlandTiles2 = this.floodSearch( + this.lobePos2, + (tile) => tile > WATER + ); // grow shore - const shoreTiles1 = lowlandTiles1.filter((pos) => this.data[pos] == 0); + const shoreTiles1 = lowlandTiles1.filter((pos) => this.data[pos] == WATER); this.dropWithin(shoreTiles1); - const shoreTiles2 = lowlandTiles2.filter((pos) => this.data[pos] == 0); + const shoreTiles2 = lowlandTiles2.filter((pos) => this.data[pos] == WATER); this.dropWithin(shoreTiles2); // seed beach - const beachTiles = lowlandTiles1.filter((pos) => this.data[pos] == 1); + const beachTiles = lowlandTiles1.filter((pos) => this.data[pos] == BEACH); this.dropWithin(beachTiles); // expand forest - const forestLobe = this.floodSearch(this.lobePos1, (tile) => tile > 1); - const forestTiles = forestLobe.filter((pos) => this.data[pos] == 2); + const forestLobe = this.floodSearch(this.lobePos1, (tile) => tile > BEACH); + const forestTiles = forestLobe.filter( + (pos) => this.data[pos] == LIGHT_FOREST + ); this.dropWithin(forestTiles); this.dropWithin(forestTiles); this.dropWithin(forestTiles); // form mountain - const mountainTiles = this.floodSearch(this.basePos, (tile) => tile > 4); + const mountainTiles = this.floodSearch( + this.basePos, + (tile) => tile > MOUNTAIN + ); this.dropWithin(mountainTiles); // GENERATOR // const erodePos = islandTiles[islands.rng() % islandTiles.length]; diff --git a/island/render.ts b/island/render.ts index a7a3903..b5a92da 100644 --- a/island/render.ts +++ b/island/render.ts @@ -1,3 +1,4 @@ +import { BEACH, DENSE_FOREST, LIGHT_FOREST, MOUNTAIN, WATER } from "./data"; import { IslandGrid } from "./grid"; export function renderIslands( @@ -8,19 +9,19 @@ export function renderIslands( for (let x = 0; x < islands.width; x++) { const tile = islands.data[islands.xy(x, y)]; switch (tile) { - case 0: + case WATER: cx.fillStyle = "blue"; break; - case 1: + case BEACH: cx.fillStyle = "yellow"; break; - case 2: + case LIGHT_FOREST: cx.fillStyle = "#00ff00"; break; - case 3: + case DENSE_FOREST: cx.fillStyle = "#008800"; break; - case 4: + case MOUNTAIN: case 5: case 6: case 7: