Line data Source code
1 : #include "core/animations/states/LegsJumpAnimationState.hpp"
2 :
3 : #include "core/animations/states/LegsStandAnimationState.hpp"
4 : #include "core/animations/states/LegsFallAnimationState.hpp"
5 : #include "core/animations/states/LegsProneAnimationState.hpp"
6 :
7 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
8 :
9 : #include "core/physics/Constants.hpp"
10 : #include "core/entities/Soldier.hpp"
11 :
12 : namespace Soldank
13 : {
14 0 : LegsJumpAnimationState::LegsJumpAnimationState(const AnimationDataManager& animation_data_manager)
15 0 : : AnimationState(animation_data_manager.Get(AnimationType::Jump))
16 0 : , animation_data_manager_(animation_data_manager)
17 : {
18 0 : }
19 :
20 0 : std::optional<std::shared_ptr<AnimationState>> LegsJumpAnimationState::HandleInput(Soldier& soldier)
21 : {
22 0 : if (soldier.control.prone) {
23 0 : return std::make_shared<LegsProneAnimationState>(animation_data_manager_);
24 : }
25 :
26 0 : if (!soldier.control.up) {
27 0 : if (soldier.on_ground) {
28 0 : return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
29 : }
30 :
31 0 : return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
32 : }
33 :
34 0 : if (GetFrame() == GetFramesCount()) {
35 : // If holding A or D, don't change animation. TODO: figure out why soldat does it and
36 : // improve explanation
37 0 : if (!soldier.control.left && !soldier.control.right) {
38 0 : if (soldier.on_ground) {
39 0 : return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
40 : }
41 :
42 0 : return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
43 : }
44 :
45 0 : if (soldier.on_ground) {
46 : auto maybe_running_animation_state =
47 : CommonAnimationStateTransitions::TryTransitionToRunning(soldier,
48 0 : animation_data_manager_);
49 0 : if (maybe_running_animation_state.has_value()) {
50 0 : return *maybe_running_animation_state;
51 : }
52 0 : }
53 : }
54 0 : return std::nullopt;
55 : }
56 :
57 0 : void LegsJumpAnimationState::Update(Soldier& soldier, const PhysicsEvents& physics_events)
58 : {
59 0 : soldier.stance = PhysicsConstants::STANCE_STAND;
60 :
61 0 : if ((GetFrame() > 8) && (GetFrame() < 15)) {
62 0 : glm::vec particle_force = soldier.particle.GetForce();
63 0 : particle_force.y = -PhysicsConstants::JUMPSPEED;
64 0 : soldier.particle.SetForce(particle_force);
65 : }
66 0 : }
67 : } // namespace Soldank
|