added shoreline to tiles

This commit is contained in:
evanpelle
2024-08-22 08:00:18 -07:00
parent 0f4510f387
commit 7517f933ca
4 changed files with 58 additions and 8 deletions
+2
View File
@@ -39,7 +39,9 @@ export class PlayerInfo {
export interface Tile {
isLand(): boolean
isShore(): boolean
isWater(): boolean
isShorelineWater(): boolean
owner(): Player | TerraNullius
hasOwner(): boolean
isBorder(): boolean
+11 -5
View File
@@ -1,6 +1,6 @@
import {EventBus} from "./EventBus";
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, MutableBoat, BoatEvent} from "./Game";
import {TerrainMap, TerrainType} from "./TerrainMapLoader";
import {Terrain, TerrainMap, TerrainType} from "./TerrainMapLoader";
export function createGame(terrainMap: TerrainMap, eventBus: EventBus): Game {
return new GameImpl(terrainMap, eventBus)
@@ -17,13 +17,19 @@ class TileImpl implements Tile {
private readonly gs: GameImpl,
public _owner: PlayerImpl | TerraNulliusImpl,
private readonly _cell: Cell,
private readonly _terrain: TerrainType
private readonly _terrain: Terrain
) { }
isShore(): boolean {
return this.isLand() && this._terrain.shoreline
}
isShorelineWater(): boolean {
return this.isWater() && this._terrain.shoreline
}
isLand(): boolean {
return this._terrain == TerrainType.Land
return this._terrain.type == TerrainType.Land
}
isWater(): boolean {
return this._terrain == TerrainType.Water
return this._terrain.type == TerrainType.Water
}
borders(other: Player | TerraNullius): boolean {
@@ -213,7 +219,7 @@ export class GameImpl implements MutableGame {
this.map[x] = new Array(this._height);
for (let y = 0; y < this._height; y++) {
let cell = new Cell(x, y);
this.map[x][y] = new TileImpl(this, this._terraNullius, cell, terrainMap.terrain(cell).terrainType);
this.map[x][y] = new TileImpl(this, this._terraNullius, cell, terrainMap.terrain(cell));
}
}
}
+35 -3
View File
@@ -29,7 +29,8 @@ export enum TerrainType {
}
export class Terrain {
constructor(public terrainType: TerrainType) { }
public shoreline: boolean = false
constructor(public type: TerrainType) { }
}
export async function loadTerrainMap(): Promise<TerrainMap> {
@@ -56,6 +57,37 @@ export async function loadTerrainMap(): Promise<TerrainMap> {
return new TerrainMap(terrain);
}
function process(terrain: Terrain[][]) {
function process(map: Terrain[][]) {
for (let x = 0; x < map.length; x++) {
for (let y = 0; y < map[0].length; y++) {
const terrain = map[x][y]
const ns = neighbors(x, y, map)
if (terrain.type == TerrainType.Land) {
if (ns.filter(t => t.type == TerrainType.Water).length > 0) {
terrain.shoreline = true
}
} else {
if (ns.filter(t => t.type == TerrainType.Land).length > 0) {
terrain.shoreline = true
}
}
}
}
}
function neighbors(x: number, y: number, map: Terrain[][]): Terrain[] {
const ns: Terrain[] = []
if (x > 0) {
ns.push(map[x - 1][y])
}
if (x < map.length - 1) {
ns.push(map[x + 1][y])
}
if (y > 0) {
ns.push(map[x][y - 1])
}
if (y < map[0].length - 1) {
ns.push(map[x][y + 1])
}
return ns
}
+10
View File
@@ -5,7 +5,11 @@ import {Theme} from "./Config";
export const pastelTheme = new class implements Theme {
private background = colord({r: 100, g: 100, b: 100});
private land = colord({r: 244, g: 243, b: 198});
private shore = colord({r: 234, g: 343, b: 188});
private water = colord({r: 160, g: 203, b: 231});
private shorelineWater = colord({r: 150, g: 193, b: 221});
private territoryColors: Colord[] = [
colord({r: 255, g: 179, b: 186}), // Vibrant Light Pink
colord({r: 255, g: 223, b: 186}), // Vibrant Peach
@@ -77,8 +81,14 @@ export const pastelTheme = new class implements Theme {
terrainColor(tile: Tile): Colord {
if (tile.isLand()) {
if (tile.isShore()) {
return this.shore
}
return this.land;
} else {
if (tile.isShorelineWater()) {
return this.shorelineWater
}
return this.water;
}
}