1
Programming / Beginner Question: How should maps relate to objects?
« on: November 22, 2015, 06:50:08 PM »
Recently I have studied the Complete Roguelike Tutorial, using python+libtcod (http://www.roguebasin.com/index.php?title=Complete_Roguelike_Tutorial,_using_python%2Blibtcod) and I have been trying to implement some of the ideas with Python 3 and PyGame. Mostly I have been thinking about basic things like how objects should be modelled, how to split the required tasks to separate files etc. More sophisticated things like procedural generation of dungeons and Field of View algorithms are not top priority. I (suppose) am a novice in programming so a lot of the problems I have are probably elementary. I can do basic stuff like player object moving inside a map (list of lists of Tile objects).
If I have understood the code of the tutorial correctly, when going to the next map the new map is written over the old map. What if I want to keep the old maps and their contents?
I think maps should have their own class, but what I'm wondering is how the maps should relate to objects within them. Should maps have a 'list of objects' attribute that keeps track of what objects are inside it? Should the objects have an attribute or a function that identifies the map that they are inside of? Both? I would like to know how is this problem has been solved by more experienced people. The tutorial has a global variables 'map' and 'objects' (the list of objects). I think what I want is a list or a dictionary of maps. I am assuming the game is structured in a way that is similar to the tutorial (object composition etc).
If I have understood the code of the tutorial correctly, when going to the next map the new map is written over the old map. What if I want to keep the old maps and their contents?
I think maps should have their own class, but what I'm wondering is how the maps should relate to objects within them. Should maps have a 'list of objects' attribute that keeps track of what objects are inside it? Should the objects have an attribute or a function that identifies the map that they are inside of? Both? I would like to know how is this problem has been solved by more experienced people. The tutorial has a global variables 'map' and 'objects' (the list of objects). I think what I want is a list or a dictionary of maps. I am assuming the game is structured in a way that is similar to the tutorial (object composition etc).