Battle System Design

86 views
Skip to first unread message

Michele Rullo

unread,
Aug 7, 2014, 8:24:22 AM8/7/14
to ash-fr...@googlegroups.com
Hello everyone,

I have a design question that I am not able to answer by myself. I am writing a small battle game following the ECS paradigm: there are a lot of entities which will engage fights. How would you suggest to implement a "fight" system in order to keep everything decoupled?

Example: entity "A" chase entity "B". "A" manages to reach for "B" and it starts to attack. How would you implement the attack action? Would you use a message queue with a FSM for each entity, or would you write a "BattleSystem" which handles the fights?

Thank you in advance.

James Wrightson

unread,
Aug 7, 2014, 10:42:06 AM8/7/14
to ash-fr...@googlegroups.com
Well "entity "A" chase entity "B" is locomotion, so some kind of steering behaviour system should be running
allowing A to chase B.

Then A will need an AI system to check the distance for B, and then attack B via an AttackSystem or something similar...

I would make the attack system directly attack B by providing an "AttackedBy" component, which stores the player A and any attack details.

Finally B should have an AI system that can read the "AttackedBy" component and react accordingly :)

Alternatively the AttackSystem could dispatch an "AttackMessage" and the BAiSystem can read and process that message asynchronously.

My MessageBuffer  can easily handle the async message aspect :D

Michele Rullo

unread,
Aug 7, 2014, 11:19:37 AM8/7/14
to ash-fr...@googlegroups.com
Thank you for your answer.

At the moment I have a ControlSystem wich handles the keyboard and mouse events. When the player clicks on screen the character attacks: if there is an entity close to him it will be attacked. I found interesting the idea to attach components to "communicate" among entities. So, I should write a FightSystem which handles all the entities with an "AttackedBy" component right?

I would avoid the second approach, I really like the idea that each System can live on its own without communicating with the others :)

Another problem I have it's the following: I have an AnimationSystem which takes care to pick the right animation frame at the right moment. When the player choose to attack (clicking the mouse button) the ControlSystem takes care to switch the animation by accessing the AnimationComponent and changing the coordinates for the sprite sheet. The same applies to an AISystem, for instance. Now, imagine a very big game with plenty of entities with different animations.. The AISystem should have "knowledge" of each animation data associated to each type of entity.. It would become easily a mess. How to avoid this? How to write Systems which are agnostic to gameplay data?

I hope the questions are clear :)

Thank you.

James Wrightson

unread,
Aug 7, 2014, 11:55:53 AM8/7/14
to ash-fr...@googlegroups.com
"I should write a FightSystem which handles all the entities with an "AttackedBy" component right? "
- That is a good idea, I would handle it on the "node added" though, as you could have multiple "AttackedBy" components added in a single update.


"I would avoid the second approach, I really like the idea that each System can live on its own without communicating with the others :)"
- In theory it sound's good but in practice, if your game is < 40K Lines of Code I really would not worry. It is much faster to handle communication via the message route.
I have used it on an 80K LOC project and it was very maintainable.

I think many devs new to ECS theory consider decoupling, but omit ease of use, consistency and cohesion. All important factors with any software design ;)


"How to write Systems which are agnostic to gameplay data?"
- The simplest way is to represent each animation via a string-id. Then grab the animation based on id, using that string, from the AnimationComponent.

Alternatively, use a model-view-controller pattern for the complex display and pass the controller to the systems that handle animation changes.

Hope it helps :D

Michele Rullo

unread,
Aug 8, 2014, 8:05:17 AM8/8/14
to ash-fr...@googlegroups.com

Thank you so much for your answers, really precious for me!
Reply all
Reply to author
Forward
0 new messages