Difference between revisions of "Complete roguelike tutorial using C++ and libtcod - part 3: dungeon building"
(pasted →A hole digging map) |
(pasted →The implementation) |
||
Line 30: | Line 30: | ||
We replace the setWall function by a function that digs a rectangular zone. We also make a declaration that will allow some BspListener class to use the protected dig function. The BspListener class is not declared in the header because it's private to the Map class. The createRoom function will dig the room and populate it with actors. | We replace the setWall function by a function that digs a rectangular zone. We also make a declaration that will allow some BspListener class to use the protected dig function. The BspListener class is not declared in the header because it's private to the Map class. The createRoom function will dig the room and populate it with actors. | ||
==The implementation== | |||
We define some constants for the room size range : | |||
static const int ROOM_MAX_SIZE = 12; | |||
static const int ROOM_MIN_SIZE = 6; | |||
The static keyword, when used on a global variable means that the variable is not visible from outside the .cpp file. |
Revision as of 11:46, 29 September 2015
Complete roguelike tutorial using C++ and libtcod -originally written by Jice Text in this tutorial was released under the Creative Commons Attribution-ShareAlike 3.0 Unported and the GNU Free Documentation License (unversioned, with no invariant sections, front-cover texts, or back-cover texts) on 2015-09-21. |
---|
|
In this article, we will improve the Map class to generate a real dungeon with rooms and corridors. We'll use a very simple dungeon generator, using a straightforward way to connect rooms together. This will result in "winnable" dungeons (no room disconnected) but with a slightly chaotic look. For a better corridor connection, check the libtcod C++ samples in the libtcod/samples/ directory.
libtcod functions used in this article
TCODBsp::traverseInvertedLevelOrder
A hole digging map
Whereas we were adding walls in an empty map in the last article, this time, we will dig holes in a map full of walls. We need to change the Map class declaration for that :
Tile() : canWalk(false) {}
Tiles not default to non-walking.
protected :
Tile *tiles;
friend class BspListener;
void dig(int x1, int y1, int x2, int y2);
void createRoom(bool first, int x1, int y1, int x2, int y2);
};
We replace the setWall function by a function that digs a rectangular zone. We also make a declaration that will allow some BspListener class to use the protected dig function. The BspListener class is not declared in the header because it's private to the Map class. The createRoom function will dig the room and populate it with actors.
The implementation
We define some constants for the room size range :
static const int ROOM_MAX_SIZE = 12; static const int ROOM_MIN_SIZE = 6;
The static keyword, when used on a global variable means that the variable is not visible from outside the .cpp file.