Skip to content

Commit

Permalink
feat: more biomes
Browse files Browse the repository at this point in the history
Add swamp biomes.
Add hill biome.
Increase world size.
Improve world gen algorithm.
  • Loading branch information
seifer8ff committed Feb 19, 2024
1 parent d7f1843 commit 8dc3e19
Show file tree
Hide file tree
Showing 149 changed files with 87 additions and 14 deletions.
8 changes: 4 additions & 4 deletions dist/app.js

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/autotile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ export class Autotile {
return false;
}

if (
tileBiome?.biome == "swampdirt" &&
neighborBiome?.biome == "grassland"
) {
return false;
}

if (tileBiome?.biome == "hills" && neighborBiome?.biome == "grassland") {
return false;
}

if (
tileBiome?.biome == "grassland" &&
neighborBiome?.biome == "forestgrass"
Expand Down
4 changes: 2 additions & 2 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class Game {
// RNG.setSeed(1234);

// sensible default
let width = 150;
let height = 150;
let width = 350;
let height = 350;
let fontSize = 20;

// how/why should this change?
Expand Down
37 changes: 30 additions & 7 deletions src/map-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class MapWorld {
this.adjacencyMap = {};
this.dirtyTiles = [];
this.landHeight = 0.5;
this.valleyScaleFactor = 1.5;
this.valleyScaleFactor = 2;
this.edgePadding = 0;
this.islandMask = 0.3;
this.islandMask = 0.38;
}

generateMap(width: number, height: number): void {
Expand Down Expand Up @@ -93,11 +93,11 @@ export class MapWorld {
// add different octaves of frequency
// some small hills, some large, etc
// 1 / octave * this.getScaledNoise(noise, octave * noiseX, octave * noiseY)
let height = 0.333 * this.getScaledNoise(noise, 3 * noiseX, 3 * noiseY);
height += 0.1667 * this.getScaledNoise(noise, 6 * noiseX, 6 * noiseY);
height += 0.06667 * this.getScaledNoise(noise, 15 * noiseX, 15 * noiseY);
height += 0.045 * this.getScaledNoise(noise, 22 * noiseX, 22 * noiseY);
height = height / (0.3 + 0.1667 + 0.067 + 0.045); // scale to between 0 and 1
let height = 0.7 * this.getScaledNoise(noise, 3 * noiseX, 3 * noiseY);
height += 0.5 * this.getScaledNoise(noise, 4 * noiseX, 4 * noiseY);
height += 0.3 * this.getScaledNoise(noise, 8 * noiseX, 8 * noiseY);
height += 0.3 * this.getScaledNoise(noise, 15 * noiseX, 15 * noiseY);
height = height / (0.4 + 0.5 + 0.3 + 0.2); // scale to between 0 and 1

height = Math.pow(height, this.valleyScaleFactor); // reshape valleys/mountains

Expand Down Expand Up @@ -205,6 +205,29 @@ export class MapWorld {
if (
Tile.inRange(heightVal, Tile.Biomes.grassland.generationOptions.height)
) {
if (Tile.inRange(heightVal, Tile.Biomes.hills.generationOptions.height)) {
return Tile.Biomes.hills;
}

if (
Tile.inRange(
heightVal,
Tile.Biomes.swampdirt.generationOptions.height
) &&
!this.isAdjacentToTerrain(x, y, [Tile.Biomes.dirt, Tile.Biomes.ocean])
) {
if (
Tile.inRange(
heightVal,
Tile.Biomes.swampwater.generationOptions.height
) &&
this.isAdjacentToTerrain(x, y, [Tile.Biomes.swampdirt])
) {
return Tile.Biomes.swampwater;
}
return Tile.Biomes.swampdirt;
}

if (
Tile.inRange(
heightVal,
Expand Down
41 changes: 40 additions & 1 deletion src/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export type BiomeType =
| "dirttextured"
| "sand"
| "oceandeep"
| "forestgrass";
| "forestgrass"
| "hills"
| "swampdirt"
| "swampwater";

export interface Biome {
biome: BiomeType; // basic identifier for the tileset
Expand Down Expand Up @@ -115,6 +118,18 @@ export class Tile {
},
},
},
hills: {
biome: "hills",
autotilePrefix: "biomes/hills/hills_grassland_",
color: "#e48989",
season: Season.Spring,
generationOptions: {
height: {
min: 0.75,
max: 1,
},
},
},
forestgrass: {
biome: "forestgrass",
autotilePrefix: "biomes/forestgrass/forestgrass_grassland_",
Expand Down Expand Up @@ -161,6 +176,30 @@ export class Tile {
},
},
},
swampdirt: {
biome: "swampdirt",
autotilePrefix: "biomes/swampdirt/swampdirt_grassland_",
color: "#665b47",
season: Season.Spring,
generationOptions: {
height: {
min: 0.5,
max: 0.7,
},
},
},
swampwater: {
biome: "swampwater",
autotilePrefix: "biomes/swampwater/swampwater_swampdirt_",
color: "#39512f",
season: Season.Spring,
generationOptions: {
height: {
min: 0.57,
max: 0.62,
},
},
},
sand: {
biome: "sand",
autotilePrefix: "biomes/sand/sand_dirt_",
Expand Down

0 comments on commit 8dc3e19

Please sign in to comment.