Loading game data from a text file map
Rather than having to create and place every GameObject on the screen by hand for every level of a game, a better approach can be to create the text files of rows and columns of characters, where each character corresponds to the type of GameObject that is to be created in the corresponding location.
In this recipe, we’ll use a text file and a set of prefab sprites to display a graphical version of a text data file, for a screen from the classic game NetHack:
Figure 10.7: The level we’ve created from a text file level description
In the 10_04
folder, we have provided the following two files for this recipe:
level1.txt
: A text file representing a levelabsurd128.png
: A128
x128
sprite sheet for NetHack
The level data came from the NetHack Wikipedia page, while the sprite sheet came from SourceForge: