add terrain to map

This commit is contained in:
evanpelle
2024-08-30 22:01:08 -07:00
parent 6aacffc27d
commit 8b2c2a13c0
8 changed files with 133 additions and 6 deletions
+3 -1
View File
@@ -62,7 +62,9 @@
* PERF: more efficient spawns DONE 8/30/2024 * PERF: more efficient spawns DONE 8/30/2024
* PERF: load terrain map async DONE 8/30/2024 * PERF: load terrain map async DONE 8/30/2024
* if completely surrended, lose piece of land DONE 8/30/2024 * if completely surrended, lose piece of land DONE 8/30/2024
* Add terrain elevation to map * Add terrain elevation to map DONE 8/30/2024
* Have terrain affect attack
* improve pastel territory colors
* PERF: enable CDN * PERF: enable CDN
* enable load balancing metrics * enable load balancing metrics
* end game when no players left (or after 1 hour or so?) * end game when no players left (or after 1 hour or so?)
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 834 KiB

+1 -1
View File
@@ -1,5 +1,5 @@
import {Cell} from './Game'; import {Cell} from './Game';
import binAsString from "!!binary-loader!../../resources/World.bin"; import binAsString from "!!binary-loader!../../resources/TopoWorldMap.bin";
export class TerrainMap { export class TerrainMap {
constructor(public readonly tiles: Terrain[][]) { } constructor(public readonly tiles: Terrain[][]) { }
+1 -1
View File
@@ -16,7 +16,7 @@ export const devConfig = new class extends DefaultConfig {
} }
numBots(): number { numBots(): number {
return 250 return 0
} }
startTroops(playerInfo: PlayerInfo): number { startTroops(playerInfo: PlayerInfo): number {
+5 -1
View File
@@ -90,7 +90,11 @@ export const pastelTheme = new class implements Theme {
if (tile.isShore()) { if (tile.isShore()) {
return this.shore return this.shore
} }
return this.land; return colord({
r: 174 + 5 * tile.magnitude(),
g: 163 + 5 * tile.magnitude(),
b: 128 + 5 * tile.magnitude()
})
} else { } else {
const w = this.water.rgba const w = this.water.rgba
if (tile.isShorelineWater()) { if (tile.isShorelineWater()) {
+3
View File
@@ -80,6 +80,9 @@ export class PlayerExecution implements Execution {
const tiles = bfs(firstTile, filter) const tiles = bfs(firstTile, filter)
const modePlayer = this.mg.player(mode) const modePlayer = this.mg.player(mode)
if (modePlayer == null) {
console.warn('mode player is null')
}
for (const tile of tiles) { for (const tile of tiles) {
modePlayer.conquer(tile) modePlayer.conquer(tile)
} }
+55 -2
View File
@@ -44,7 +44,7 @@ export class Terrain {
} }
export async function loadTerrainMap(): Promise<void> { export async function loadTerrainMap(): Promise<void> {
const imagePath = path.resolve(__dirname, '..', '..', 'resources', 'maps', 'World.png'); const imagePath = path.resolve(__dirname, '..', '..', 'resources', 'maps', 'TopoWorldMap.png');
const readStream = createReadStream(imagePath); const readStream = createReadStream(imagePath);
const img = await PImage.decodePNGFromStream(readStream); const img = await PImage.decodePNGFromStream(readStream);
@@ -59,11 +59,64 @@ export async function loadTerrainMap(): Promise<void> {
for (let y = 0; y < img.height; y++) { for (let y = 0; y < img.height; y++) {
const color = img.getPixelRGBA(x, y); const color = img.getPixelRGBA(x, y);
const alpha = color & 0xff; const alpha = color & 0xff;
const blue = (color >> 8) & 0xff;
if (alpha < 20) { // transparent if (alpha < 20) { // transparent
terrain[x][y] = new Terrain(TerrainType.Water); terrain[x][y] = new Terrain(TerrainType.Water);
} else { } else {
terrain[x][y] = new Terrain(TerrainType.Land) terrain[x][y] = new Terrain(TerrainType.Land)
terrain[x][y].magnitude = 0
// 150 -> 220
switch (true) {
case (blue > 220):
terrain[x][y].magnitude = 14;
break;
case (blue > 215):
terrain[x][y].magnitude = 13;
break;
case (blue > 210):
terrain[x][y].magnitude = 12;
break;
case (blue > 205):
terrain[x][y].magnitude = 11;
break;
case (blue > 200):
terrain[x][y].magnitude = 10;
break;
case (blue > 195):
terrain[x][y].magnitude = 9;
break;
case (blue > 185):
terrain[x][y].magnitude = 8;
break;
case (blue > 180):
terrain[x][y].magnitude = 7;
break;
case (blue > 175):
terrain[x][y].magnitude = 6;
break;
case (blue > 170):
terrain[x][y].magnitude = 5;
break;
case (blue > 165):
terrain[x][y].magnitude = 4;
break;
case (blue > 160):
terrain[x][y].magnitude = 3;
break;
case (blue > 155):
terrain[x][y].magnitude = 2;
break;
case (blue > 150):
terrain[x][y].magnitude = 1;
break;
default:
terrain[x][y].magnitude = 0;
break;
}
} }
} }
} }
@@ -73,7 +126,7 @@ export async function loadTerrainMap(): Promise<void> {
processDistToLand(shorelineWaters, terrain) processDistToLand(shorelineWaters, terrain)
processOcean(terrain) processOcean(terrain)
const packed = packTerrain(terrain) const packed = packTerrain(terrain)
const outputPath = path.join(__dirname, '..', '..', 'resources', 'World.bin'); const outputPath = path.join(__dirname, '..', '..', 'resources', 'TopoWorldMap.bin');
fs.writeFile(outputPath, packed); fs.writeFile(outputPath, packed);
} }