HW #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 in the Silicon Valley section must use the C++ language and the SFML library (or similar -- check with instructor first) for this homework assignment. Students in the main campus section may use any technology.

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).

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. Coverting 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:

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

  • Submit source code of your final terrain generation system, either via a Zip file to a shared Google Drive folder, or a link to GitHub.
  • Also submit an image that is representative of the kind of terrain tilemap your generator creates.
  • For #5, also submit a video showing animation of your generated terrain tilemap.