How to procedurally generate Zelda how to do in java

How can I make a procedure created in Java? The game itself is similar if Zelda was procedurally generated ... Help?

-4
source share
2 answers

The legend of Zelda cards, due to some time, uses an isometric view of the tile. The first thing you need to do is load the isometric plate into your program, which I am sure you can find Zelda tile sets. Then you will need to decide how you want your card to be processed procedurally. Will there be oceans, different biomes, construction? All of these points should be taken into account when creating your equation for creating your map. Each fragment must be saved somewhere, so I would make a 2d array to pack all your tile values. Then use the nesting loop to render the fragments. The code will 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 

generates which tiles go where a little more complicated, and then draws the tiles after they are created. Above was just an empty matrix. I would again use the for loop to fill the world to my taste with various id values ​​representing fragments. This, however, would be completely random, so you need some method for your insanity. I would test the surrounding tiles during creation and give the surrounding tiles a higher probability of generation, so that the terrain is smoother. If you need the same world for every game you play, you can just put your matrix with constant values, rather than generate them. I'm not going to write an entire isometric viewer, but I hope some of these concepts can help you.

+2
source
  • Isometric engine

    First of all, you need a functional isometric engine. The hex grid is a bit complicated (especially if you are a beginner), I suggest you start with a square grid. This means that you need to be able to load / save a map of your world. And roughly visualize it somewhere. Later you can add pan editing, etc., but this is not important yet. For example, look at this:

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

  • Terrain generator

    You need to divide map creation into several separate steps.

    • Altitude Map Generator

      Create a 2D-height pseudo-random map (with the same x, y resolution as your isometric map), which you will later transfer to your isometric map. I suggest you use the Diamond-square algorithm . Also see:

      Where you can find my C ++ implementation.

    • Converting a height map to an isometric map of the area

      Simply rescale the Z range of the height map to the maximum supported height of your isometric map. Then clean the isometric map. And finally, all cells cell(x,y,0)...cell(x,y,height(x,y)) are filled with pieces of terrain. This will result in a pseudo-random map, but will only be done with cubes (sharp voxel fronts). Thus, this requires further filtering.

    • Filter out small holes

      It depends on what shapes your slabs support. if you cannot smooth the edges on small holes with them, fill them with cubes before applying smoothing.

    • Smooth edges

      Find a certain slope of the relief and fill it with the edged tile.

    Here is an example of a partially flattened pseudo-random terrain created in this way:

    example

    I left the border cells of the map without anti-aliasing, so you see what I mean by smoothing and outputting to the station.

  • Card generator

    Now that you have the landscape, you can add other features. like changing surface slabs to different materials, adding watter, buildings, roads, trees, grass, ... Just make a loop where you arbitrarily get the x,y position and type of object, and then set it on top of the relief ... To make more Realistically, you need to use some rules, such as watter, sand, grass, rocks, snow, depending on height, buildings can only be placed on a flat surface, etc.

0
source

Source: https://habr.com/ru/post/1245860/


All Articles