Homework #2 - Noise and Terrain Generation

In this assignment you will use a noise function to create a tile-based terrain map suitable for a 2D game.

Students must use the C++ language and the SFML library (or similar -- check with instructor first) for this homework assignment. 

Resources

The following resources will be especially helpful for this assignment:

libnoise: a C++ noise library, including noiseutils, which has built in functions for terrain generation (see especially Tutorial 3 on terrain generation).

SFML: see the TileMap example in the tutorial on Designing your own entities with vertex arrays

This assignment can be viewed as requiring the careful combination of the above tutorials.

Overview 

This assignment has several conceptual pieces:

Input:

Height and width of the tile array

A tileset giving graphic tiles representing the different land types (along with its tilesize, such as 16x16 or 32x32). You may choose any tileset you wish, though this tileset will work well for this assignment (see containing page for more information). OpenGameArt.org has many tileset examples.

Processing steps:

1. Create an array of noise values. Using a noise function (Perlin noise or other), generate an array of floating point numbers (typically doubles in C++). This involves choosing a region in noise space to sample from. This is covered in the section, "Generating a Terrain Height Map" in libnoise Tutorial #3.

2. Converting this noise array into (typically integer) values that represent the different terrain types. For example, noise values between -1.00 and 0.10 might map to water, which is represented by the integer value 1. 

3. Rendering the integer array into a visual representation on screen. This involves creating a rectangular array of rectangles the size of each tile, and then texturing each rectangle with the appropriate tile texture. For example, if the tile at (5,5) has integer value of 1 (water), then the water texture from the tileset should be applied to the rectangle representing tile 5,5. See the TileMap example for how to approach this using SFML.

4. Once you have a working terrain generator, add a keyboard mapping to change the seed for the generator (this will have the effect of changing the generated terrain). noise::module::Perlin has a setSeed() function that will do this.

Performing the above 4 steps is sufficient for a B+ (passing grade) on this assignment. For an A grade do #5 or #6 below, and for an A+ grade do #5 and #6.

5. Most tilesets have specific tiles to handle transitions between terrain types, to create a better looking map that doesn't have harsh transitions on tile boundaries. Add a post-processing step that analyzes your integer tile array and adds transition tiles as appropriate. This will involve horizontal, vertical, and corner transitions. Your chosen tileset may not have tiles for every possible transition type, so only implement transitions for supported types. It is not necessary to create new transition tile graphics.

6. Most noise libraries are able to generate noise in 3 or more dimensions. This tile generation exercise only uses two dimensions, leaving at least one free for other uses. Create a loop that will iterate through this third dimension, treating it as time. For each new third dimension value, regenerate the tile map (including tile transitions). This will give the impression of animating the terrain as it changes over geologic time. It is recommended to add interative controls to adjust the time between updates, and the step size for moving through the third dimension.

Submission

  • Share your source code with me on GitHub.
  • Also submit an image that is representative of the kind of terrain tilemap your generator creates into the shared Google Drive folder for the assignment.
  • For #5, also submit a video showing animation of your generated terrain tilemap by editing the "Homework #2" shared Google doc.

Resources

You might find it useful to use a tile editor program like Tiled (http://www.mapeditor.org/) to get the coordinates/IDs of specific tiles in a tile map.

This article has some discussion on how to achieve nice looking tile transitions: http://www.squidi.net/three/entry.php?id=166.

Some sample tilesets that have good terrain type transition tiles can be found at:

Or, consider creating a dungeon as your "terrain" for extra challenge, using this pixel art tileset: Pixel Tileset: Temple / Dungeon by Colin Brown on itch.io.