# pvigier's blog

computer science, programming and other ideas

## Vagabond – Teleporting into Dungeons

Hi everyone!

Last two weeks, I was working on teleporting the players from one map to another. I will use this system to enter into dungeons, buildings, etc. and also to leave them. But it was not that easy to implement as it required some deep architectural changes in the game engine.

# A multilayer world

In a 2D top-down game, it is hard to make an open-world with only one map like Minecraft. It would mean it is not possible to go underground or upstairs in buildings. Thus, I need to be able to display several maps and to go from one map to another using doors.

But it is easier said than done. In particular for a multiplayer game, as there may be several players on different maps, and so you must manage several maps simultaneously. While in a single-player game, you just keep the map where the player is currently on.

Moreover, when I store the position of an entity, not only I must store its x and y coordinates but also the map on which it is. More precisely, as the world can be quite large, it is cut in chunks so I store the indices of the chunk on which the entity is currently on.

Previously, I was using a data structure like this one:

struct Position
{
float x;
float y;
};


And now, I am using something like that:

struct Position
{
// Chunk id
int i;
int j;
int k;
// Offset
float x;
float y;
};


This little change in the Position data structure forced me to rework my physics engine and other systems.

# Teleportation system

Once these architectural changes were done, I was ready to implement my teleportation system. As I use an entity-component-system, implementing this was just creating a new component and a new system.

The door component just contains a destination:

struct DoorComponent
{
Position destination;
}


The door system receives collision messages from the physics engine. If a collision occurs between an entity that has a door component and another entity, it transports the other entity at the door’s destination. Nothing difficult, once all the other systems are in place.

And it works well, even in multilayer mode where there are two players on different maps:

# Dungeon entrances

Finally, I worked on a dungeon entrance generator. Nothing fancy but it works well and you can change the materials of the walls to match the one used in the dungeon:

# Conclusion

That’s all for this devlog.

Next week, I will work on monsters and add them inside the dungeons. That will be a big step!

See you next week for more!

If you are interested in my adventures during the development of Vagabond, you can follow me on Twitter.

Tags: vagabond

Subscribe to the newsletter if you do not want to miss any new article: