everyone. I'm kinda new to game dev, I saw the idea of the ESC system and I'm inlove with it. I wanted to integrate something like that in my game, so I started rewriting my code.
. I have a World, that has a Manager attached to it. This manager takes care of all the Systems attached to this world that we will iterate over and use to update our game. Also the manager takes care of the Entities of the World. Every System and every Entity can have a Component attached to them. In the System the component represents the actual Components of every Entity that it's responsible for updating. On the other hand the Entity's Components are just condition (or behaviours) of the Entity. Like the player can walk, run, jump etc...
Everything seems to be fine I guess. The problem is when I want to perform the actions of updating the actual components. I can't wrap my head around of what to pass to the System. How do I know what entity I have to update? I'm using JS by the way. So lets say I have a eventListener attached to the window object. Whenever a player presses a KEY I want to update his position. I have a PositionComponent that is attached to my Player entity that has a ID generated by the following line of code
createEntity(components) {
const id = (new Date().getTime()) & 0xffffffff; // Generate random 32 bit integer
let mappedComponents = [];
components.forEach((component) => {
mappedComponents.push({
[component.name]: component,
});
});
this.entities.set(id, mappedComponents);
return id;
}
Now this bad boy is a Entity with a ID and has a Component attached to it. But I also have like 10 more enemy entities with the same Component as the Player. How am I supose to determine who is moving? I just don't seem to get this part.