-5

How would I go about making a procedurally generated map in java? The game itself is like if Zelda was procedurally generated... Help?

comander derp
  • 63
  • 1
  • 9

2 Answers2

3

The legend of Zelda maps from a while ago use a isometric tile view. The first thing you would need to do is load a isometric tile set into your program which I'm sure you can find Zelda tile sets. You then would need to decide how you want your map to procedurally generate. Will there be oceans, different biomes, building? All of theses need to be taken into consideration when making your equation for generating your map. Each tile needs to be stored somewhere so i would make a 2d array to pack all of your tile values in. Then use a nested for loop to render the tiles. The code would look something like this

int[][] world = new int[50][50];

for( int i = 0; i < 50; i++ ){
    for( int b = 0; b < 50; b++ ){
        int tile = world[i][b];
        render(tile, i, b);
        //use i and b to position the tile on your world

generating which tiles go where is a bit more tricky then rendering the tiles once they are created. Above only a empty matrix has been made. I would use a for loop again to fill the world to your liking with different int id values that represent tiles. This however would be at complete random so you need some method to your madness. I would test the surrounding tiles when generating and give the surrounding tiles a higher probability to generate so the terrain would be more smoothed out. If you want the same world for every game you play you can just supply your matrix with constant values instead of generating them. I don't intent on writing a entire isometric view engine, but i hope some of these concepts can help you out.

Ryan
  • 1,972
  • 2
  • 23
  • 36
1
  1. Isometric engine

    First of all you need to have functional isometric engine. Hexagonal grid is a bit tricky (especially if you a rookie) I suggest you start with square grid instead. That means you need to be able to load/save map of your world. And of coarse visualize it somewhere. Later you can add panning editing etc but that is not important for now. For example look at this:

    You can find there early version of mine very simple isometric engine in C++.

  2. Terrain generator

    You need to divide the generation of map into few separate steps.

    1. Height map generator

      Create pseudo-random 2D height map (with the same x,y resolution as your isometric map) that you will later turn into your isometric map. I suggest you use Diamond-square algorithm. Also have a look at:

      Where you can find mine C++ implementation.

    2. Convert height map into isometric terrain map

      Simply rescale the Z range of the height map into your max supported height of your isometric map. Then clear your isometric map. And lastly all cells cell(x,y,0)...cell(x,y,height(x,y)) fill with terrain cubes. This will result in a pseudo random map but done only with cubes (sharp voxel-ated edges). So this needs further filtering.

    3. Filter out small holes

      This depends on what shapes are supported by your tiles. if you can not smooth edges on small holes with them then fill them with cubes before applying smoothing.

    4. Smooth edges

      Find specific slope of the terrain and fill it with edged tile.

    Here example of partially smoothed pseudo-random terrain generated in this way:

    example

    I left the border cells of map un-smoothed so you see what I mean by smoothing and voxel-ated output.

  3. Map generator

    Now when you have terrain you can add another features. like changing surface tiles to different materials, adding watter, buildings, roads, trees, grass,... Just do a loop where you randomly obtain x,y position and feature type, then set it on top of terrain ... To make it more realistic you need to use some rules like watter,sand,grass,rocks,snow are height dependent, buildings can be placed only on flat area, etc.

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380