Sign in to follow this  

Basic 2D tile map design

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm currently delving into my first map system. I wrote some basic design documents, and as I began to implement it, I thought that maybe my design was a bit too redundant, or just unnecessary for my task. I'm using python for a tile based, overhead, 2d map system. My conflict, I believe, is in how I handle the tiles themselves. This is the class heirarchy: World class (The controller for the entire game) ----/\ tMap class (Contains list of tiles, and controls scrolling and such) ----/\ tile class (Contains tile level data) Each class contains a list of all objects, and 4 other lists for some specific types of objects: Turfs, objs, mobs, and areas. I do this so I can search through these lists on different scales. For instance, if I need to check for a mob somewhere on the map, I would access tMap's mobs list, and just search through it, or if I wanted to search for an obj at a specific tile, and search that tiles objs list. Now, what I'm curious about here, is if this is an efficient approach, or if it would be better to perhaps limit the tile class, or even remove all together? I was also concerned, since I'm developing this in python with pygame's assistance, if a system such as this could use too much memory or operate too slowly on larger maps due to pythons overhead? I'm not very well at describing myself, and I apologize for it. But if anything seems unclear, please let me know so I may attempt to describe myself better.

Share this post


Link to post
Share on other sites
Only two things strike me as odd.

First, why does tMap control scrolling and such? A group of tiles shouldn't care about presentation issues. You'll be better off in the long run by seperating the game Map from the view of the Map.

Secondly, if there's a lot of mobs, and expect to search for them often, you might want to look for a different data structure than a list. [don't know python, so don't know what's available]

[edit: otherwise the general setup seems fine to me]

Share this post


Link to post
Share on other sites
In the portion of the code that displays the map to the player. Usually that code is kept seperate so that the game map is more focused, and more easily used by other parts that never need scrolling [like for AIs or a dedicated server].

Share this post


Link to post
Share on other sites
Separating tile display from tile maps as game state is a standard design pattern: the distribution of responsibilities between a model and its view.
This articulation creates an useful interface that allows:
- Multiple models with the same view (in this case different map data structures, either to experiment or for different map types, and stubs to test visualization without setting up actual gameplay).
- Multiple views with the same model (in this case simultaneous and different visualizations of the same game and different "engines" like overhead, isometric and Wolfenstein-like 3D).
- Use of the model without being encumbered by the view, as Telastyn suggests.

Lorenzo Gatti

Share this post


Link to post
Share on other sites

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this