Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm creating a text RPG in Java, but I think this applies for a GUI as well with regard to the data structure. Each Level is a tiled map. Each Tile object has an (X,Y) coordinate, and references to adjacent tiles, but my question is with regard to storing object and NPC data on that Tile object. Depending on the size of the map I'm loading, this seems like a lot to load, but if that is the commonly accepted practice then I'll go with it.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I'm not sure where the problem is that you're asking about. If you need the data, you have to load it. I would personally keep NPCs in a separate list, and track them separately from all the actual tile data. That's how I make these kinds of games.

Because you only need to draw the tiles on-screen; but entities (NPCs) may have collision logic, events, etc. and should always be tracked, regardless of their position.

If you're worried about performance, then I say, don't; just code it, and if problems arise, you have working code to profile and optimize.

Edit: The way that I would code it would be to have a 2D array of tiles; each tile has the XY coordinates of the image that it displays, a "walkable" attribute, etc. NPCs/entities would be kept in a separate list, and they would either hold a tile XY coordinates for the tile they're stepping on, or hold a reference to a Tile object with an X and Y.

share|improve this answer
    
When you say "keep them in a separate list", how do you store your reference between an NPC and a tile? For instance, a battle with a certain group of NPCs only occurs when a player enters a tile? –  Brian Reindel Apr 4 '11 at 17:53
1  
I'm guessing that this question is about managing large-scale maps with tons of stuff on them. In that case, I would keep one ADT with the tile data (tile image coordinates, walkable or not, etc.) and one with a list of all the NPCs. To give a C# reference, I would probably have a 2D array of some Tile class with ImageX, ImageY, etc. properties and a List<T> of some sort of Entity/NPC class that would have Tile XY coordinates. –  ashes999 Apr 4 '11 at 18:03
    
How do you store the reference between the Tile class and the NPCs in the Entity/NPC class? Is your tile coordinates your "key"? –  Brian Reindel Apr 4 '11 at 19:17
1  
I think I've used two approaches: the Entity has (TileX, TileY) coordinates, and (more recently) the Entity has a Tile reference, which in turn, has a (TileX, TileY) coordinate. As for the tiles, I would store them in an array, not a hashmap. –  ashes999 Apr 4 '11 at 19:23
    
Awesome, thanks so much for your help! –  Brian Reindel Apr 4 '11 at 19:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.