Line data Source code
1 : #include "core/animations/states/LegsJumpSideAnimationState.hpp"
2 :
3 : #include "core/animations/states/LegsCrouchAnimationState.hpp"
4 : #include "core/animations/states/LegsRollBackAnimationState.hpp"
5 : #include "core/animations/states/LegsStandAnimationState.hpp"
6 : #include "core/animations/states/LegsFallAnimationState.hpp"
7 : #include "core/animations/states/LegsRunBackAnimationState.hpp"
8 : #include "core/animations/states/LegsRunAnimationState.hpp"
9 : #include "core/animations/states/LegsJumpAnimationState.hpp"
10 : #include "core/animations/states/LegsProneAnimationState.hpp"
11 :
12 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
13 :
14 : #include "core/entities/Soldier.hpp"
15 : #include "core/physics/Constants.hpp"
16 :
17 : namespace Soldank
18 : {
19 0 : LegsJumpSideAnimationState::LegsJumpSideAnimationState(
20 0 : const AnimationDataManager& animation_data_manager)
21 0 : : AnimationState(animation_data_manager.Get(AnimationType::JumpSide))
22 0 : , animation_data_manager_(animation_data_manager)
23 : {
24 0 : }
25 :
26 0 : std::optional<std::shared_ptr<AnimationState>> LegsJumpSideAnimationState::HandleInput(
27 : Soldier& soldier)
28 : {
29 0 : if (!soldier.control.left || !soldier.control.right) {
30 0 : soldier.control.was_running_left = soldier.control.left;
31 : }
32 :
33 0 : bool jumping_direction_left = soldier.control.was_running_left;
34 :
35 0 : if (soldier.control.prone) {
36 0 : return std::make_shared<LegsProneAnimationState>(animation_data_manager_);
37 : }
38 :
39 0 : if (soldier.control.jets) {
40 0 : if ((soldier.control.left && soldier.direction == 1) ||
41 0 : (soldier.control.right && soldier.direction == -1)) {
42 0 : return std::make_shared<LegsRollBackAnimationState>(animation_data_manager_);
43 : }
44 :
45 0 : if (soldier.jets_count > 0) {
46 0 : if (soldier.on_ground) {
47 0 : return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
48 : }
49 0 : return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
50 : }
51 : }
52 :
53 0 : if (!soldier.control.up && !soldier.control.down && !soldier.control.left &&
54 0 : !soldier.control.right) {
55 0 : if (soldier.on_ground) {
56 0 : return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
57 : }
58 0 : return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
59 : }
60 :
61 0 : if (!soldier.control.up && !soldier.control.down) {
62 : auto maybe_running_animation_state =
63 0 : CommonAnimationStateTransitions::TryTransitionToRunning(soldier, animation_data_manager_);
64 0 : if (maybe_running_animation_state.has_value()) {
65 0 : return *maybe_running_animation_state;
66 : }
67 0 : }
68 :
69 0 : if (soldier.control.up && soldier.on_ground) {
70 0 : if (!soldier.control.left && !soldier.control.right) {
71 0 : return std::make_shared<LegsJumpAnimationState>(animation_data_manager_);
72 : }
73 :
74 0 : if (soldier.control.left || soldier.control.right) {
75 : // Chain jumping to the side
76 0 : if (GetFrame() == GetFramesCount()) {
77 0 : return std::make_shared<LegsJumpSideAnimationState>(animation_data_manager_);
78 : }
79 : }
80 : }
81 :
82 0 : if (soldier.control.down && soldier.on_ground) {
83 0 : if (!soldier.control.left && !soldier.control.right) {
84 0 : return std::make_shared<LegsCrouchAnimationState>(animation_data_manager_);
85 : }
86 :
87 : auto maybe_crouch_running_animation_state =
88 : CommonAnimationStateTransitions::TryTransitionToCrouchRunning(soldier,
89 0 : animation_data_manager_);
90 0 : if (maybe_crouch_running_animation_state.has_value()) {
91 0 : return *maybe_crouch_running_animation_state;
92 : }
93 0 : }
94 :
95 0 : if (!jumping_direction_left) {
96 0 : if ((GetFrame() > 3) && (GetFrame() < 11)) {
97 0 : glm::vec2 particle_force = soldier.particle.GetForce();
98 0 : particle_force.x = PhysicsConstants::JUMPDIRSPEED;
99 0 : particle_force.y = -PhysicsConstants::JUMPDIRSPEED / 1.2F;
100 0 : soldier.particle.SetForce(particle_force);
101 : }
102 : }
103 :
104 0 : if (jumping_direction_left) {
105 0 : if (GetType() == AnimationType::JumpSide) {
106 0 : if ((GetFrame() > 3) && (GetFrame() < 11)) {
107 0 : glm::vec2 particle_force = soldier.particle.GetForce();
108 0 : particle_force.x = -PhysicsConstants::JUMPDIRSPEED;
109 0 : particle_force.y = -PhysicsConstants::JUMPDIRSPEED / 1.2F;
110 0 : soldier.particle.SetForce(particle_force);
111 : }
112 : }
113 : }
114 :
115 0 : return std::nullopt;
116 : }
117 :
118 0 : void LegsJumpSideAnimationState::Update(Soldier& soldier, const PhysicsEvents& /*physics_events*/)
119 : {
120 0 : soldier.stance = PhysicsConstants::STANCE_STAND;
121 0 : }
122 : } // namespace Soldank
|