2024.js/island/render.ts

42 lines
1 KiB
TypeScript
Raw Normal View History

2024-01-13 11:44:36 -05:00
import { BEACH, DENSE_FOREST, LIGHT_FOREST, MOUNTAIN, WATER } from "./data";
2024-01-13 11:34:25 -05:00
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) {
2024-01-13 14:54:25 -05:00
case -3:
case -2:
case -1:
cx.fillStyle = "#000088";
break;
2024-01-13 11:44:36 -05:00
case WATER:
2024-01-13 11:34:25 -05:00
cx.fillStyle = "blue";
break;
2024-01-13 11:44:36 -05:00
case BEACH:
2024-01-13 11:34:25 -05:00
cx.fillStyle = "yellow";
break;
2024-01-13 11:44:36 -05:00
case LIGHT_FOREST:
2024-01-13 11:34:25 -05:00
cx.fillStyle = "#00ff00";
break;
2024-01-13 11:44:36 -05:00
case DENSE_FOREST:
2024-01-13 11:34:25 -05:00
cx.fillStyle = "#008800";
break;
2024-01-13 11:44:36 -05:00
case MOUNTAIN:
2024-01-13 14:02:40 -05:00
case MOUNTAIN + 1:
2024-01-13 14:24:48 -05:00
case MOUNTAIN + 2:
2024-01-13 11:34:25 -05:00
cx.fillStyle = "#666666";
break;
default:
cx.fillStyle = "#88aaff";
break;
}
cx.fillRect(x, y, 1, 1);
}
}
}