Tile Game Questions

Hello. I’m currently trying to build a tile-based game and I have run into a few problems… hopefully not the average ‘how do I display my map?’ newbie questions…

My tile game has buildings. There are several types of buildings. Each type of building is a class, of course. Some buildings, however, span multiple tiles. What’s the best way to keep track of all my buildings, where they belong, etc? I know a 2-d array would do it easily for single tile buildings, but for buildings which cover multiple tiles, I’m not sure how to do it easily and efficiently. How can I take any point on my 2d tile map, and determine which object that map position represents? I don’t think it would be too good to insert the same instance of the building into each point on the map that the building covers… or is that the best way?

Looking for input…
thanks,
JOn

Well, if this is a small single player game then you’re probably doing it entirely in Actionscript. The best way to do it then would be as follows:

You have a MainMap class which is your actual on screen map with tiles that have buildings etc. You have Map classes which have 1-d arrays of all the objects on the map (ie: mapObjects[0] = building729, mapObjects[1] = tree386, etc.). MainMap has a loadMap method that takes all the info from a Map class from its mapObjects array.

Every object that can be displayed on a map should extend a MapObject class. This class should have a property for coordinates that can handle more than specific coordinates (ie: x3-5y1 would be a recangular object that took up the coordinates (3,1), (4,1), and (5,1)). You can really use whatever syntax or methodology you want to accomplish that.

The loapMap method of MainMap can read each array and take the coordinate property of each MapObject in the array to determine where to place them. You can also have loadMap create a 2d array which keeps track of MapObject instanced based on a coordinate key if you want (ie: stuffOnTheMap[xCoord][yCoord] = building867). That would mean instances larger than 1x1 would be referenced by multiple coordinate keys.

It it’s a larger game or a mulit-player game you should DEFINITELY be using PHP for all your map stuff though.