Tracking item and monster positions

121 Views Asked by At

I've been working on a libtcod/C++ roguelike, and I've run into a small problem.

When the player goes between floors, the items from the previous floor stay on the new map, ending up in the walls, and each time I go between floors, more items generate until the map is swamped.

Is there any way to save a particular floor (perhaps with the seed) so that the actors' current x/y is preserved for reloading later?

1

There are 1 best solutions below

8
On

Create a Map class which stores the map details (walls, stairs, etc), items on the floor and any monsters. Then you can create an std::map<int, Map> with the key being the floor number.

Then whenever you change floors you check the std::map to see if the Map object for that floor exists, if it does load it, if not create a new Map.