-1

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

  • You could use perlin noise to generate your map and biomes. I found [this](https://www.youtube.com/watch?v=fjZAgoxFKiQ) video really insightful. – Dugnom May 05 '22 at 10:31
  • see [Island generator with biomes](https://stackoverflow.com/a/36647622/2521214) for some ideas ... in case of isometric or tiles see also [generating tile map](https://stackoverflow.com/a/36263999/2521214) – Spektre May 06 '22 at 07:15

1 Answers1

2

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.

  • Thank you, I'll read this. I already took a peek and it seems like a simple and efficient method. Also I am sure Microsoft changed every good thing in Minecraft :) – Michel Beṭar May 05 '22 at 11:01
  • thx for the link +1 ... btw alternatives to **Perlin + Biome Rules** and **[Diamond&Square + Biome Rules](https://stackoverflow.com/a/36647622/2521214)** approaches usually uses Voronoi diagrams IIRC along with graph algorithms but those looked to complicated for my taste so I came up with the stuff In the link above instead. – Spektre May 06 '22 at 12:17