Just a simple way to organize Entities in a 2D array.

Started by
9 comments, last by Squared'D 10 years, 11 months ago
Well let's think this out. First, what are your use cases and why do you need the array? Is it for collision detection, quick selection with a mouse, displaying the entities, or all of the above? Some entities can take up more than once space. Is this the same for units or just buildings? If a building is at a location, can a unit be there? Can more than one building be at the same location? These are questions that you need to ask yourself. If only buildings will take more than one location and are static, should they be treated the same as moving units?

For big objects, you can store them indirectly in the map. Like you stated, you can have topright, bottomleft, etc objects that just serve as placeholders. They're not real entities, and they point back to their parent which is the real entity. You'll still only need to update an entity only once since the place holders aren't real entities and don't need to go in the main entity list. When something moves, just move the real entity, and you can have it move it's place holders. That's just one option.

Learn all about my current projects and watch some of the game development videos that I've made.

Squared Programming Home

New Personal Journal

This topic is closed to new replies.

Advertisement