Choosing the tile textures

Until now we've been loading a prebuilt level from a text file. This level file already knew which textures needed to be used and where they should be used, but since we're now generating them procedurally, that's not the case. We need to decide which tiles should have which sprites.

The if/else approach

A common way of approaching this is simply to create a monstrous if/else statement. In principle, it's a simple task; define each tile through a series of if statements and set the right tile. However, in reality, you end up with a complex mess of code that is very difficult to read.

Imagine a situation where you have a tile set of fifty possible variants. The amount of code required to choose which tile goes where would ...

Get Procedural Content Generation for C++ Game Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.