I am using Artemis ECS. I have the very basics of a game already. I am now trying to determine how to gracefully handle input and to a lesser extent collisions. Some people say with ECSs, everything should be a component and data driven and you shouldn't really use events/messages, or at least avoid them where possible.
Input handling in component based design covers what I am asking as well, but I would understand when and how to raise events, add components or whatever much more fully by using a game we all know (Angry Birds) as an example.
So, for Angry Birds I would have some entities with components (where components are pure data, and an entity is just an id):
- catapult (position, sprite, state{free, available}?, clickable?, dragable? releasable?)
- bird (position, velocity, physics{density}, sprite)
- baddy (position, velocity, physics {density}, sprite, health)
- box (position, velocity, physics{density}, sprite, health)
And the following systems to start with:
- SpriteSystem (has all entities with sprite component)
- PhysicsSystem (has all entities with position, velocity and physics components)
- HealthSystem (has all entities with health component)
- InputSystem (knows about keyboard/mouse events such as clicked, dragged, released, key down etc, not sure what entities should have...)
How would the InputSystem interact with other Systems to say the catapult was clicked, and if there are birds left, and none are in flight, allow it to be dragged and release/fire the bird.
Would the InputSystem modify ClickableComponent, DragableComponent and ReleasableComponents on the catapult entity? Or, should it raise some sort of Click, Drag and Release Events? What System would listen for the component changes/events? A CatapultSystem perhaps?
When the PhysicsSystem notices a collision between the bird and a baddy, should it create a Collision event, that I guess the HealthSystem would listen for? Or again, should it modify a collision Component already on the Entity?
Collision and click components would need to be cleared every game loop if I took the component approach (seems a bit naff...)