Hello dear community,
currently, I am thinking about how actions should be implemented in an entity component based game. Let me describe this with the following example:
Let’s say the player controls a monster. This monster can fire some actions for example it can ‘attack’, it can ‘scream’ and maybe some other things… . So, ‘attack’ and ‘scream’ would be two different types of actions. Also, there can only be one action being fired at a time per entity, so it is not possible to scream and attack at the same moment.
My current approach looks as follows: When the player presses a certain button (e.g. “F”) it is checked if the entity already has an Action component and if it does not, a new Action component will be added which contains the type of action (e.g. “attack”). This can easily be done by an enum which lists all actions plus their duration. After the time (duration) is up, the Action component is removed again, so that a new action can be fired.
Later, I want to play specific animations and/or do some audio output for each action.
However, is the way I described a good approach or should I change something? This probably can be done this way but I just wanted to ask you guys before I go over and code this.