Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Recommended architecture to allow entities to access each other's data.  (Read 2508 times)
0 Members and 1 Guest are viewing this topic.
Offline unlight
« Posted 2016-12-26 04:14:28 »

Hi guys,

I'm looking for some advice or resources on game programming patterns / architectures that are most appropriate to handle interactions between entities in games. To give some background, I am currently designing a game mechanic where projectiles are launched in space and affected by the orbital gravity of planets (similar to Angry Birds in Space). In this case, the projectile entities need to be aware of the positions of the planet entities in order to calculate their velocities due to gravity. They also need to be aware of other projectile entities for collision detection.

After doing some research I have come up with the following potential solution:

  • Create an entity management class to store reference to all entities.
  • Pass entity manager to entities during construction.
  • During game loop update, the projectile objects can access the planet objects via the entity manager class to calculate velocity and collision detection.

However, it seems like the point of having an entity manager is so that the entity manager can perform the collision detection so that the entity classes do not need to know of one another. However, the entity manager would then also need to calculate the velocities for each projectile, per update, and this is where i get confused.

I get that I can simply pass a planet entity list to the projectile class update function, but what about in big games where many entities require information on each other to function correctly?

I would really appreciate if anyone can share any resources that could help me build a pretty architecture for this, or how they handle these types of interactions themselves.

Getting my head around programming architectures is the reason I enjoy game programming.
Offline 65K
« Reply #1 - Posted 2016-12-26 07:35:31 »

When you need to look at the whole picture or need all objects of a kind for a task, it is a good approach to create new separate classes that perform such tasks. But don't call any class "Manager". It the most abused and meaningless name you can think of. What you want is a physics simulation and collision detection. It might make sense to integrate both into one PhysicsSimluator or have two classes. Depends on your approach on physics simulation.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Offline unlight
« Reply #2 - Posted 2016-12-26 08:06:20 »

This does sound like a cleaner approach, do you happen to know of any resources or examples that I could have a look through? I'm having difficulty finding the right words to Google.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tariqbroadnax

Junior Devvie

Medals: 5
Exp: 3 years

« Reply #3 - Posted 2016-12-26 09:01:25 »

I recommend:

  • Create a Scene class that stores and updates everything related to your game
  • Create a CollisionManager class that checks for collisions. The Scene class should store the CollisionManager and update it.
  • Create a data structure that group entities by their location for faster collision detection and faster access of entities in certain areas
  • Give a every entity a reference to the scene so that they can access any entity
  • Have every relevant entity store a list of vectors for each force/accel that they are feeling
  • Have every relevant entity update its position and vel based on these vectors
  • Create a Planet class that gives and updates force vector to every relevant entity
Offline 65K
« Reply #4 - Posted 2016-12-26 09:25:00 »

The basic architecture is (and should be) very simple, for example:
public class EntityModel {
   List<Entity> getEntities();
   List<Entity> getPlanets();
   List<Entity> getProjectiles();

public class PhysicsSimulator {
   public void update(long time) {
      // place to tear your hair by simulating gravity effects...
      for (Entity entity : entities) {
   private EntityModel entityModel;

Think of having controllers and models. Controllers do the action and know the model. Not vice versa.
This will massively help in keeping code dependencies and data flow under control.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Offline unlight
« Reply #5 - Posted 2016-12-26 12:44:29 »

Wow, thank you so much for the advice guys. I wouldn't have thought to maintain my projects in this way, there is still much to learn about effective software development!
Pages: [1]
  ignore  |  Print  

EgonOlsen (59 views)
2018-06-10 19:43:48

EgonOlsen (41 views)
2018-06-10 19:43:44

EgonOlsen (61 views)
2018-06-10 19:43:20

DesertCoockie (240 views)
2018-05-13 18:23:11

nelsongames (142 views)
2018-04-24 18:15:36

nelsongames (141 views)
2018-04-24 18:14:32

ivj94 (883 views)
2018-03-24 14:47:39

ivj94 (144 views)
2018-03-24 14:46:31

ivj94 (795 views)
2018-03-24 14:43:53

Solater (159 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!