Procedural Square World Generation Example

Discussion in 'Tutorials' started by Puhloo, Aug 12, 2016.

  1. Puhloo

    Puhloo Member

    Joined:
    Jun 21, 2016
    Posts:
    9
    GM Version: GM:Studio (Works on Legacy GM)
    Target Platform: All
    Download: .gmz file , .exe demo

    Summary:
    This is basically an example which shows how a world is generated using the diamond square algorithm/method. You can also easily apply this to your own game by simply taking the script!

    Tutorial:
    So what is diamond square algorithm? Also known as random midpoint displacement fractal, it is a method for randomly generating heightmaps for computer graphics. The diamond-square algorithm starts with a 2D grid then randomly generates terrain height from four seed values arranged in a grid of points so that the entire plane is covered in squares. (Taken from Wikipedia)

    The example itself shows how a world is generated using 3 differently generated maps to create a biome somehow is based on this graph that I found in stackexchange:
    [​IMG]
    As for the mountains and water, it is all based in elevation. Basically there are 3 grids that are combined to generate a biome map like below. (Humidity, Temperature, & Elevation)
    [​IMG]
    A 640 x 640 map. Each pixel is a biome.

    If you play the .gmz file or open the demo, you can press SPACE to restart the room and press Z to zoom in at the pointed area.
     
  2. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    155
    Pretty cool! I would recommend seeding the temperature noise so the top (or somewhere) is colder than the bottom for more realistic biome distribution. Here is one I made a long time ago also using midpoint displacement:

    [​IMG]

    Snow is at the top, jungle at the bottom. (Code was a complete mess though. Broke with a GMS update.)
     
    slojanko and Puhloo like this.
  3. Puhloo

    Puhloo Member

    Joined:
    Jun 21, 2016
    Posts:
    9
    Yeah I actually considered seeding the temperature noise but since it's just an example, well why bother? Thanks for stating that though!
     
  4. OhGoodShepherd

    OhGoodShepherd Member

    Joined:
    Jun 29, 2016
    Posts:
    6
    Thanks for this example. I enjoyed seeing how it works and am experimenting with it now. I have a collection of world generation, chunk, noise and related tutorials though am having terrible trouble learning how to go from world generation to something like a top down exploration game... I'll keep poking away but if anyone has any suggestions for tutorials on where to go next from something like this - I'd love to see!

    Thanks again!
     
  5. gnysek

    gnysek Member

    Joined:
    Jun 20, 2016
    Posts:
    1,304
    Two additions should be that temperatures are based on Latitude, and it would be good if result is seamless, so you can infinity scroll.
     
  6. yokun51

    yokun51 Member

    Joined:
    Feb 6, 2017
    Posts:
    6
    I don't know if someone will reply me, but I want to know how to use this procedural generation to create a level. Like replacing all pixel with an instance, blue pixel with a water bloc of 32x32 pixel, green pixel with a grass bloc of 32x32 pixel, etc. If someone can help me with that it could be awesom.
     
  7. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,119
    For a System like this you just shouldn't use instances at all, your computer cannot handle that.
     
  8. Deadlyapples

    Deadlyapples Member

    Joined:
    Apr 17, 2017
    Posts:
    24
  9. whale_cancer

    whale_cancer Member

    Joined:
    Jun 29, 2016
    Posts:
    399
    I've implemented this on a small scale (where N is never higher than 4). It seems that the corners and edges always look weird? That is to say, they show more variance than the middle of the map. What am I missing? Is it not possible to use this on such a small scale?

    Six examples. Corners are set semi-randomly. The darker colors are deeper. The final colors are determined by integers, while the actual generated values are real numbers (is that my problem?)
    [​IMG]
    Edit: Just read this on the wiki "...who described it as flawed because the algorithm produces noticeable vertical and horizontal "creases" due to the most significant perturbation taking place in a rectangular grid." I guess I can just discard the edges and keep the middle, then?
     
    Last edited: Apr 20, 2017
    slojanko likes this.
  10. yokun51

    yokun51 Member

    Joined:
    Feb 6, 2017
    Posts:
    6
    What can we use instead of instances?
     
  11. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,119
    Depends on what you need. You can go with tiles if it isn´t too many or grids like ds_grid or a 2D array.
     
  12. yokun51

    yokun51 Member

    Joined:
    Feb 6, 2017
    Posts:
    6
    If I use a grid, how can I draw all my sprite? And for now I want to use tile, but I dont know if it will be efficient if I have a huge world
     
  13. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,119
    Here is a good resource that will get you started in this whole proceedual thing.
     
  14. yokun51

    yokun51 Member

    Joined:
    Feb 6, 2017
    Posts:
    6
    Thanks you a lot I will watch that for sure.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice