Dungeon hallway building tile map

I'm working on a basic dungeon generator right now. I have gotten it to build rooms and walls my problem lies with the tunnels connecting them. This is an example of what is now generated there is more but it will work as an example



The hash-tags are suppose to represent tunnels. Using my current way (One room at a time select start and ending doorways, an if point less than destination go down, if it is greater go up until we get there then use that as the next starting point) some maps I cannot get the tunnels to generate. Because the tunnels cannot go through floor or wall spaces it gets stuck. What is a better way to get a tunnel to connect all my rooms. I looked into A* but it is beyond the scope of the class I'm in now. I'm using a vector of vectors of objects that represent each tile. Any help on how to get my rooms connected is appreciated. If I can't find a solution I will have to delete my code and retry building the paths first then putting the rooms on top.
I think it boils down to the data structure you have.

I would have a Tile class which stores what occupies it & what type of terrain it is (Wall, Grass, Mud, Tunnel etc), A room is a 2d array of Tiles, and a GameMap is a std::list of Rooms.

When the player occupies a tile that is a tunnel, the next room loads and the player's position is updated to the appropriate position in the new room.

I am not sure whether you you know about classes or not.

I imagine the game being like Tomb Raider where all these things are lying around to be acquired by players.

I would also use polymorphism to help with this. By that I mean there is a class hierarchy with GamePiece as the base class. Under that there are classes for all different kinds of Players, Enemies & resources such as weapons, treasure, relics, medi-packs etc. A Tile can be occupied by a GamePiece, which is reflected in the definition of the Tile Class member:

GamePiece *OccupiedBy;

and the member function that sets a Tile:

void setOccupied(GamePiece * ThePiece) {
    OccupiedBy = ThePiece;

But when the function called:


This works because a pointer to a derived class object is a valid pointer to a base class.

Hope all goes well.

I am going out now - it's Friday night here - so I may be able to answer until tomorrow.

Topic archived. No new replies allowed.