for example i have monster control
inside:
player position
move logic
attack logic
animation
how to divide into components so that they interact with each other inside
Yes. If you look at OpenKeeper, this is exactly what I have done. That is the central place of querying all entities and components. I have also wrapped some entities (like what is essentially a character/creature) to controllers which do the queries hidden with API. But yes, that is it.
Separate the logic and the visuals. Even if it is simple like:
EntityVisual extends Component {
private string model = “derp.j3o”;
}
And then your visual side (AppState perhaps) just tries to find entities that have this component to visually represent them. Together maybe with Position component that tells the entity position.
EntityVisual extends Component {
private string model = “derp.j3o”;
//load spatial
//setup control to spatial
}
public class HealthComponent extends Component {
public float health;
public HealthComponent(float health)
{
this.health = health;
}
public float getHealth()
{
return health;
}
}
class MyControll extends AbstractControl{
//update loop
//getting components
}
Just pass EntityID (the control serves a single entity, right?) and instance of the EntityData to your AbstractControl like you would pass any Java object.
Remember that Components are just like database rows… just properties. No logic. Logic goes to Systems. A visual representation of your entity, whether it is based on AbstractControl or something else, is essentially one System. Although it probably doesn’t alter the logic state, just the link between a 3D object and your data.
Please look at the example links provided earlier. Those in the actual component repository are very simple and as such are excellent learning material. OpenKeeper is a massive working multiplayer ECS example of sorts. Primarily the Zay ES examples.
All this depends on what are your ultimate plans. Like multiplayer or not. Although, I would make all games so that they are designed as kinda multiplayer. Like a server - client type.
Could not find method compile() for arguments [com.simsilica:zay-es:1.2.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I recon you are using newer version of Gradle that doesn’t have compile anymore. It is effectively replaced by implementation. Well, not so simple but read some docs if you are interested. I’ll guess implementation will work.