Line data Source code
1 : #include "core/animations/states/LegsProneAnimationState.hpp"
2 :
3 : #include "core/animations/states/LegsGetUpAnimationState.hpp"
4 : #include "core/animations/states/LegsProneMoveAnimationState.hpp"
5 :
6 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
7 :
8 : #include "core/entities/Soldier.hpp"
9 : #include "core/physics/Constants.hpp"
10 :
11 : namespace Soldank
12 : {
13 0 : LegsProneAnimationState::LegsProneAnimationState(const AnimationDataManager& animation_data_manager)
14 0 : : AnimationState(animation_data_manager.Get(AnimationType::Prone))
15 0 : , animation_data_manager_(animation_data_manager)
16 : {
17 0 : }
18 :
19 0 : std::optional<std::shared_ptr<AnimationState>> LegsProneAnimationState::HandleInput(
20 : Soldier& soldier)
21 : {
22 : // Set old direction when entering state
23 0 : if (GetFrame() == 2) {
24 0 : soldier.old_direction = soldier.direction;
25 : }
26 :
27 0 : if (GetFrame() > 23) {
28 0 : if (soldier.control.prone || soldier.direction != soldier.old_direction) {
29 0 : auto new_state = std::make_shared<LegsGetUpAnimationState>(animation_data_manager_);
30 0 : new_state->SetFrame(9);
31 0 : return new_state;
32 0 : }
33 :
34 0 : if (soldier.on_ground) {
35 : auto maybe_rolling_animation_state =
36 : CommonAnimationStateTransitions::TryTransitionToRolling(soldier,
37 0 : animation_data_manager_);
38 0 : if (maybe_rolling_animation_state.has_value()) {
39 0 : return *maybe_rolling_animation_state;
40 : }
41 0 : }
42 : }
43 :
44 0 : if (GetFrame() > 25 && soldier.on_ground) {
45 0 : if (soldier.control.left || soldier.control.right) {
46 0 : return std::make_shared<LegsProneMoveAnimationState>(animation_data_manager_);
47 : }
48 : }
49 :
50 0 : return std::nullopt;
51 : }
52 :
53 0 : void LegsProneAnimationState::Update(Soldier& soldier, const PhysicsEvents& physics_events)
54 : {
55 0 : soldier.stance = PhysicsConstants::STANCE_PRONE;
56 0 : }
57 : } // namespace Soldank
|