Add constants
This commit is contained in:
parent
92a0af5457
commit
4eacd3a5aa
3 changed files with 35 additions and 14 deletions
8
island/data.ts
Normal file
8
island/data.ts
Normal file
|
@ -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;
|
|
@ -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];
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue