Instead of expensive sinkhole battle, apply deep water effect in postprocessing

This commit is contained in:
Tangent Wantwight 2024-01-13 15:21:23 -05:00
parent 4d2596fe33
commit 38f4dd1bee
2 changed files with 20 additions and 2 deletions

View File

@ -42,6 +42,7 @@ export function IslandApplet() {
ticks += 3;
if (islands.done) {
clearInterval(timerId);
islands.deepenWater();
}
renderIslands(islands, cx);

View File

@ -1,5 +1,5 @@
import { Prng, UINT_MAX, mulberry32 } from "../lib/prng";
import { BEACH, ICECAP } from "./data";
import { BEACH, ICECAP, WATER } from "./data";
import {
ALL_ISLANDS,
BIG_ISLANDS,
@ -21,7 +21,7 @@ export class IslandGrid {
done = false;
constructor(public width: number, public height: number, seed: number) {
this.data = Array(width * height).fill(-1);
this.data = Array(width * height).fill(WATER);
this.rng = mulberry32(seed);
const islandBag = this.shuffle([
@ -161,6 +161,23 @@ export class IslandGrid {
this.forCardinals(pos, action);
this.forDiagonals(pos, action);
}
public deepenWater() {
for (let i = 0; i < this.data.length; i++) {
if (this.data[i] == WATER) {
let isShore = false;
this.forNeighbors(i, (adjPos) => {
if (this.data[adjPos] > WATER) {
isShore = true;
}
});
if (!isShore) {
this.data[i] = WATER - 1;
}
}
}
}
public choose<T>(list: T[]) {
if (list.length == 0) {
throw new Error("Picking from empty list");