Fandom

Petit Computer Wiki

Terrain Generation Example

914pages on
this wiki
Add New Page
Comments60 Share

This example program shows you how to generate terrain using a simple hill algorithm. It stores values which represents the map in TMAP, which you can use in a game. I can't tell you how to integrate it into your game, but feel free to ask questions about the generator.

How it worksEdit

The algorithm creates a scaled down version of the screen. The scale is based on RES; if you set it to 1, you'll get a perfect resolution map (but it'll take forever). The default value of 4 creates 4X4 blocks. Random sized hills are then placed on the map. The hills build upon other hills, so eventually the terrain starts to get rough. This is all done in @RAISE. Afterwards, the map is normalized so that the entire terrain falls within an expected range (0-1). The terrain is flattened (even though the method is called @SHARPEN), then converted into tile information. Each tile has a value within the range 1-REGIONS, where REGIONS is the amount of colors (regions) the map can take on. Finally, the map is just drawn to the screen. This isn't a very good explanation, but this website should make everything clear: http://www.stuffwithstuff.com/robot-frog/3d/hills/index.html.

Variables for generationEdit

  • RES: Changes the resolution of the map. Larger = more blocky (try to make it a power of 2, like 1, 2, 4, 8, 16, etc.)
  • MINRAD/MAXRAD: The minimum and maximum radius of the hills. Mess with these values to change the form of the land.
  • WATER: Specifies the percentage of area which should generally be covered with water.
  • SAND,GRASS,MOUNT,SNOW: Specifies the breakup of the leftover area after the water is filled. Note that these should add up to 100!
  • GRASSL/GRASSH: Breaks up grass lands into two regions: low and high. These percentages should add up to 100 (these percentages are the portion of grass broken up into these two categories).
  • MOUNTL/MOUNTH: Same as GRASSL/GRASSH, but for mountains. Should add up to 100.
  • DEBUG: Set to 0 to remove terrain generation messages.
  • RAISENUM: Determines the number of hills to raise. Mess with this to change the form of the land.

Options (second QR set)Edit

The first set of QR codes contains just the generator. If you're looking to use this to generate maps, you'll want to use this one. The second set of QR codes (which has more) contains an options screen which allows you to change the options for terrain generation to produce whatever you like. Use this one if you just want to play around.

Here are the options (second QR set only):

  • Resolution: Lower = less blocky but slower
  • Min radius: The smallest hill size you want to generate.
  • Max radius: The largest hill size you want to generate. Make this large for smooth, large landmasses. Make it small for smaller, rougher land.
  • Roughness: How many hills to generate. Larger = slower, but more varied (and possibly smoother).
  • Water level: How high the water should be. Larger = more water.
  • Flatten: Flattens the land but keeps the high points to produce more "grasslands".
  • Sand/Grass/Mnt/Snow amnt: How much sand/grass/mountains/snow to generate. All options in yellow must add to 100. Does not correspond to "percentage"; for instance, a value of 60 in Mnt will not make it 60% mountains.
  • Water/Grass/Mnt ratio: Water, grass, and mountains have two shades. This determines the ratio between the lower elevation shade and the higher elevation shade.
  • Island mode: Creates a single island rather than a bunch of land. You should probably turn off "Flatten".
  • Noise: How much random "static" should be added to the landscape. See picture 8 in the slideshow (very high noise).

Press start to generate a new picture. Press A to save the picture and color file (also save that last MEM file so that pictures are named uniquely).

This isn't the best way to generate terrain, but Petit Computer is slow, so it's fine I guess. Let me know if you have questions!

  • Low resolution, default settings
  • Medium resolution, more varied settings.
  • High resolution, varied settings.
  • Small hill size (set MINRAD and MAXRAD to small)
  • Island mode
  • A noisy island with very few hills generated
Terrain Generator

Middle click to view full-size

Terrain Generator (w options) (2)

Middle click to view full-size

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.