The task is to create a StateMachine for the hero and for the enemies.
Some common notes:
- Each State Machine controls one entity: a hero or one of the enemies.
- These state machines will be inheritors of
StateMachine.
- In their constructors, they should accept IDs of the corresponding Mob.
- In their constructors, they should accept all settings of the Mob: attack radius, the force of the attack, initial health points, etc.
- In their constructors, they should initialize the State Machine by using the
add_state and add_transition methods of the StateMachine parent class.
- The state machines should be placed in this folder:
core/event/management/controller/statemachine/
During this task, you may want to create RadiusFilter, KeyPressedTransition, KeyHeldTransition and maybe something else as well.
Note, that Mob can perform an attack, it can jump and probably something else. So, you may want to create some helper functions to not repeat the logic of the attack twice (in each controller).
In some states you may want to change the image of the entity. It will be done in the issue #106
The attack and the jump are states of the StateMachine. Hence, they are kinds of the Controller. So, you will need to create a couple of Controllers and put them into core/event/management/controller:
Bounce makes some PhysicalEntity bounce off the ground. In the constructor, it should accept the parameters of the jump (the module of the impulse, for example) and the Image, which should be set when the jump is performed. In the control function it applies an impulse to the corresponding PhysicalEntity and changes its image.
AttackInRadius makes mob attack its enemies. Let's assume, that enemies may hit enemies as well. In the constructor, it accepts the radius of the attack and the force and the id of the entity, which performs the attack and the Image, which will represent the visual view of an attack. In the control function, it filters all entities in the given radius with `RadiusFilter, decreases their health points and sets the mob's image to the given one.
Walk makes some PhysicalEntity walk, or just move in one direction. It accepts walk animation - Image, speed and direction (would be nice to create enum Walk::Direction with two values: Left, Right). In control, just applies an impulse to move the object.
Idle makes an entity just do nothing. It should accept the animation of 'not doing nothing'.
Maybe I have missed some states, but these are essential.
I have drawn an example of the state machine for the hero, which can jump, walk and attack. You may check it out here: hero-statemachine.drawio
The task is to create a
StateMachinefor the hero and for the enemies.Some common notes:
StateMachine.add_stateandadd_transitionmethods of theStateMachineparent class.core/event/management/controller/statemachine/During this task, you may want to create
RadiusFilter,KeyPressedTransition,KeyHeldTransitionand maybe something else as well.Note, that Mob can perform an attack, it can jump and probably something else. So, you may want to create some helper functions to not repeat the logic of the attack twice (in each controller).
In some states you may want to change the image of the entity. It will be done in the issue #106
The attack and the jump are states of the
StateMachine. Hence, they are kinds of theController. So, you will need to create a couple of Controllers and put them intocore/event/management/controller:Bouncemakes somePhysicalEntitybounce off the ground. In the constructor, it should accept the parameters of the jump (the module of the impulse, for example) and theImage, which should be set when the jump is performed. In thecontrolfunction it applies an impulse to the correspondingPhysicalEntityand changes its image.AttackInRadiusmakes mob attack its enemies. Let's assume, that enemies may hit enemies as well. In the constructor, it accepts the radius of the attack and the force and the id of the entity, which performs the attack and theImage, which will represent the visual view of an attack. In thecontrolfunction, it filters all entities in the given radius with `RadiusFilter, decreases their health points and sets the mob's image to the given one.Walkmakes somePhysicalEntitywalk, or just move in one direction. It accepts walk animation -Image, speed and direction (would be nice to create enumWalk::Directionwith two values:Left,Right). Incontrol, just applies an impulse to move the object.Idlemakes an entity just do nothing. It should accept the animation of 'not doing nothing'.Maybe I have missed some states, but these are essential.
I have drawn an example of the state machine for the hero, which can jump, walk and attack. You may check it out here: hero-statemachine.drawio