Skip to main content
gamedev.net
🔒 Locked

Basic 2D tile map design

Started by Prodigal Squirrel Jan 25, 2006 at 11:52 PM 4 replies 1.7k views
Original Post
Prodigal Squirrel
Prodigal Squirrel
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.
-------------------------- Alex--------------------------
Telastyn
Telastyn
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]
Prodigal Squirrel
Prodigal Squirrel
So where should I control map scrolling?
-------------------------- Alex--------------------------
Telastyn
Telastyn
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].
LorenzoGatti
LorenzoGatti
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
Omae Wa Mou Shindeiru
Prodigal Squirrel
Prodigal Squirrel
Thanks, you two truely clarified things for me.
-------------------------- Alex--------------------------

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.