Difference between revisions of "Complete roguelike tutorial using C++ and libtcod - part 3: dungeon building"
(pasted →A hole digging map) |
|||
Line 12: | Line 12: | ||
[http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/bsp_traverse.html?c=false&cpp=true&cs=false&py=false&lua=false TCODBsp::traverseInvertedLevelOrder] | [http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/bsp_traverse.html?c=false&cpp=true&cs=false&py=false&lua=false 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; | |||
<span style="color:green">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);</span> | |||
}; | |||
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. |
Revision as of 11:44, 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.