'Making a random level generator with biome logic [closed]
I'm working on a 2d surivival game. Currently using a very basic way of level generating
enum Tile { Grass, Stone, Water; }
private int viewport_x = 0;
private int viewport_y = 0:
private Random r = new Random();
private Hashmap<Point, Tile> level = new Hashmap<Point, Tile>();
public void update(){
for(int x = viewport_x; x < viewport_x + 20; x++ )
for(int y = viewport_y; y < viewport_y + 20; y++ )
if(!level.containtsKey(new Point(x, y)))
level.put(new Point(x, y), randomTile());
}
public Tile randomTile(){
int x = r.nextInt(40);
return x <= 37 ? Tile.Grass :
x == 38 ? Tile.Stone :
x == 39 ? Tile.Water :
null;
}
as well as a method to update the viewport with the player movement.
This level generator works fine but it won't make sense if I want to add snow for example, because the level will be a random mix between grass and snow
so I'm wondering if there's a way (without using tools) to add biome logic to my generator..
Asking for the idea/algorithm no need to write any code
Solution 1:[1]
Look into perlin noise generation. Using one or two of these maps to generate a layout will make it much easier and look more realistic.
I'm not sure how minecraft does it now, but they used to have two perlin noise maps, one called heat and one called humidity.
https://medium.com/nerd-for-tech/generating-digital-worlds-using-perlin-noise-5d11237c29e9
There are alternatives but this one is a solid option for a game using biomes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sander Skovgaard Hansen |
