I’m using the Entity Component system described here. It works perfectly, but I have one question. How do I get components to be able to interact with other entities?
For example: I have a battle component that I add to an entity. I want the battle component to know if the parent entity is touching another entity, and then call the hurt() method on the entity that it is touching.
This sounds easy enough, but I’m just wondering how I get components to know where other entities are. One thing I thought of is to have an array of entities, and pass it into the components constructor. However, that would just create copies of the entities for the component, and then when the component called the hurt() method on one of them, it would call it on the copy entity, not the real entity, correct? (I’m new to java, and I’m still not sure whether it passes variables by reference or by value.)
How do I get a component to interact with the actual entities, and not copies of them?