5 Replies - 552 Views - Last Post: 17 July 2013 - 02:27 PM Rate Topic: -----

#1 Semus  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 126
  • Joined: 27-May 13

Random tile generation

Posted 23 June 2013 - 10:33 AM

I was thinking about this the other day and was wondering about the theory or theoretical implementation behind random tile generation in games like Terraria and Starbound.

Minecraft uses a different sort of seeding technique so I'll leave that out of this discussion (unless it could be done this way in a 2D environment). I believe Minecraft does use a seed, but I think it's based on perlin noise if I remember correctly.

For 2D games like Terraria and Starbound, and having never seen the source code for either, I wanted to get an idea on how these games would generate their landscapes. I wanted to see if I could come up with my own theory and see if anyone feels that it may be possible to do it this way.

I suppose using a randomly generated seed number is the best way to do this, although there may be other techniques. I was thinking that perhaps the seed could be broken into sections. For example 879284619270435902 is a random 18 digit number that could be separated in groups of two. Each group could represent a coordinate or groups of coordinates on the game grid. Then, using this same seeded number, each group could represent a specific tile set. Then linking the tile sets with the coordinates, that's where the specific tiles would go. The same could be done for buildings or trees and whatever you wanted.

I'm not exactly sure if this technique is feasible, or if it even makes sense. This is just something I was kicking around in my head.

I have no experience with this sort of thing, but I wanted to know if something like this could be done or if this is close to the way modern games generate their levels. I'll have to do a lot more research on this and yes, Google should be my first stop.

Are there any other places with good documentation on these sorts of topics? At some point I'm going to have to dive into this exact thing and wanted to get some advice.

Is This A Good Question/Topic? 0
  • +

Replies To: Random tile generation

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8379
  • View blog
  • Posts: 31,147
  • Joined: 12-June 08

Re: Random tile generation

Posted 23 June 2013 - 10:58 AM

There are many ways to go about it, but I believe Terria uses procedurally generated landscapes - similar to Minecraft (well in the 30k foot view).

While the seed is good for random input (and replicating the same random input), it is also important to have the rules that extrapolate value (not just _the_ value) from the seed, apply rules from that first generated block, and going from there.

Reading material:

https://en.wikipedia...Voronoi_diagram
http://www.gamasutra...procedural_.php
http://pcg.wikidot.c...games:minecraft
https://en.wikipedia...ural_generation
http://minecraft.ign...ins-World-Seeds
Was This Post Helpful? 0
  • +
  • -

#3 Semus  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 126
  • Joined: 27-May 13

Re: Random tile generation

Posted 23 June 2013 - 11:35 AM

Interesting reading material. I'll be sure to take a look at those.

If you have a predefined game world environment such as Terraria, you really only need to generate the game world once and that's at loading time (or the beginning of the game). I'll leave block manipulation and environment saving for another time, but it seems as if you could create the entire game world using a few seeded numbers.

I'm mostly just thinking out loud here, but it seems like the easiest thing to do would be to generate your seed numbers randomly and then each seed number would be for a specific set of entities. For example, a certain set of blocks would be generated according to the seeded number and then placed randomly within a specific set of coordinates (or pixels) in that world. Basically like this... Voronoi_diagram

I am not that into math and I don't know how complicated this is going to be, but I'm going to have to learn how to do this at some point or the game I want to make is out the window.

So here is my not so technical logic:

If (certain section of seeded number is between ** and **) then place blocks randomly within x,y coordinates, or within ** and ** pixels on the map.

This post has been edited by Semus: 23 June 2013 - 11:40 AM

Was This Post Helpful? 0
  • +
  • -

#4 grimpirate  Icon User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 714
  • Joined: 03-August 06

Re: Random tile generation

Posted 27 June 2013 - 12:47 PM

A simple method that I could come up with for generating "block" terrain like Minecraft's would be to create an array whose length is equal to side * side. I would loop through the array and I would define a range of random number generation. For instance, -9 through 9. 0 represents sea level. Then I would implement a sorting algorithm that observes certain comparisons for the topography of the terrain. The simplest would be an ascending/descending sort of the numbers. Finally, I would use this "terrain map" as the method for setting my terrain "blocks". The map itself using a descending/ascending sort would be mountainous on the northwest section and deep and ocean-like on the southeast section.

Not necessarily the terrain generation of legend, but one way to go about it quickly. You would also define different brick types for each of the height levels so as to add a degree of "realism."

The analogy works in 2d, except that you would use a different tile for each array number, representing a different height. Anything less than 0 would be a sea tile, anything greater than 0 would be some tile that specifies a change in height: desert, grass, rock, ice (as in a mountain-like transition). You could also analyze each of a tile's neighbors, as in a bicubic resize algorithm to determine if it needs to be a transition tile between two differing height numbers.

This post has been edited by grimpirate: 27 June 2013 - 12:50 PM

Was This Post Helpful? 0
  • +
  • -

#5 JTG2003  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 29-February 12

Re: Random tile generation

Posted 28 June 2013 - 12:41 PM

View Postgrimpirate, on 27 June 2013 - 12:47 PM, said:

...



I did something like this while playing around with random terrain generation last week. I had elevations 0-6 where 0 is sea level. I started with a 50x50 map of level 3 elevation tiles, then created a routine to go to each tile, look at the surrounding tiles, and randomly decide whether to raise or lower the terrain. The move was only allowed if it would cause an even slope. Here's a screenshot of one of my better ones:

Posted Image

It probably wasn't needed, but I ran about 1000 passes (looping through every tile 1000 times) to generate this. The obvious bad part is there's really not enough water. Obviously it's tough to get rivers when you're working with randomness, but I had expected to see some lakes at least.

Later I tried something where in each pass, if the terrain was lowered, add 1 to a total "dirt" count and terrain could only be raised by removing 1 from that count. The idea was trying to make the terrain more balanced overall so it wasn't all just mountains .. simulate ACTUAL land displacement instead of adding/deleting dirt. The result was more water, but due to the way I looped through the map, the lower blocks were more mountainous and the top blocks were more water.

Then I looked up how it was done in other programs and realized I was probably taking the wrong approach...
Was This Post Helpful? 0
  • +
  • -

#6 jRaskell  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 06-February 12

Re: Random tile generation

Posted 17 July 2013 - 02:27 PM

This is a good starting point on using Perlin noise to generate terrain:

http://freespace.vir...ls/m_perlin.htm

(fyi, it was the second link on a google of 'perlin noise')

A lot of different terrains can be generated by tweaking the persistance, interpolation, and smoothing of the algorithm.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1