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