Hello, recently I have been trying my hand at coding a game in C#. I'm not using XNA for this, as I thought I would learn more if I coded the game from scratch (although I am using a multimedia engine).
I'm trying to design a 2D RPG game - a bit ambitious I know, however I have a reasonably well understanding of at least the basic parts of the game (ie the 'boiler plate' code), and I've reached a part where I don't know where to go from here.
In the 2D game, you progress through the game via walking around different 'areas'. Once you hit a 'portal tile', you are transported to the next area etc.
I'm having trouble understanding how these area object should be set up. This was my first idea: Each area has a few different collection structures (for example, a visibility quadtree, a collision quadtree, an AI entity List etc). So if I were to add an enemy entity into the game, it would be put into the visibility quadtree, the collision quadtree (because you can collide with entities) and the AI entity list. When the area receives an update request, it tells each of these structures to update themselves, which in turn tell the entities to update themselves. All good, so far.
My question is this: What if this enemy needs to communicate with other objects? For example, it might need to know whether the player was in a certain range of it. Or whether it had been hit by the player. Or where all the collidable objects are in the area (so it could pathfind).
The first (and bad) solution to this problem would be simply to pass each entity a reference to each collection. But this obviously encourages tightly coupled objects, which is not good.
The second solution I came up with was for each entity to be able to query the area, via message structures. So an enemy would be able to say "Give me a list of each entity within X distance of my position" and the area would return an answer. However, this would get increasingly difficult as I would have to code more and more possibilities into the area ("Give me a list of entities that are not within X distance of myself", "Give me a list of all entities with health lower than X" etc).
What I'm looking for is a time tested solution to this problem of inter object communication, and basically how to set up an area. I suppose it would need some kind of messaging system as well, although I'm not sure.
Thanks for reading.