Way to treat game entities

I’m kinda stuck trying to find an effective way to treat the entities in my game, currently everything is stored in their own array so there is one array called terrain_content which contains the grass and rocks and soon of my map then there is one for trees, one for enemies and so on, so if i want to hit something with my sword I have to look up what is in the enemy array at the the location above the one the player is in, this poses many problems so what I’m asking is what is a good way for me to handle enemies so I can easily acquire them, run methods trough them and display them on my screen and so on?

I usually end up storing entities in two ways, one list of ALL entities for when I want to iterate over them all (like to drive game ticks or such), and one spatial structure (for example just having a List in each Tile on the level, if the level is small, or a quadtree for large levels) for quickly finding entities in an area of the world.

Storing stuff twice is slightly more bug prone, so I’d suggest just using one, however. If iterating through your spatial structure is fast, just use that one.

This sounds similar to what was discussed in this topic. Does this help solve your issues?

Component based entity system is the way to go, well, IMO :slight_smile: