2024.js/island/render.ts
2024-01-13 11:44:36 -05:00

38 lines
931 B
TypeScript

import { BEACH, DENSE_FOREST, LIGHT_FOREST, MOUNTAIN, WATER } from "./data";
import { IslandGrid } from "./grid";
export function renderIslands(
islands: IslandGrid,
cx: CanvasRenderingContext2D
) {
for (let y = 0; y < islands.height; y++) {
for (let x = 0; x < islands.width; x++) {
const tile = islands.data[islands.xy(x, y)];
switch (tile) {
case WATER:
cx.fillStyle = "blue";
break;
case BEACH:
cx.fillStyle = "yellow";
break;
case LIGHT_FOREST:
cx.fillStyle = "#00ff00";
break;
case DENSE_FOREST:
cx.fillStyle = "#008800";
break;
case MOUNTAIN:
case 5:
case 6:
case 7:
case 8:
cx.fillStyle = "#666666";
break;
default:
cx.fillStyle = "#88aaff";
break;
}
cx.fillRect(x, y, 1, 1);
}
}
}