Line data Source code
1 : #ifndef __ANIMATION_HPP__
2 : #define __ANIMATION_HPP__
3 :
4 : #include "core/animations/AnimationData.hpp"
5 :
6 : #include "core/math/Glm.hpp"
7 :
8 : #include <vector>
9 : #include <memory>
10 : #include <optional>
11 :
12 : namespace Soldank
13 : {
14 : struct Soldier;
15 : struct PhysicsEvents;
16 :
17 : class AnimationState
18 : {
19 : public:
20 : AnimationState(std::shared_ptr<const AnimationData> animation_data);
21 : AnimationState(const AnimationState& other) = default;
22 0 : virtual ~AnimationState() = default;
23 :
24 : void DoAnimation();
25 : const glm::vec2& GetPosition(unsigned int index) const;
26 : unsigned int GetFramesCount() const;
27 : bool IsAny(const std::vector<AnimationType>& animations) const;
28 :
29 0 : AnimationType GetType() const { return animation_data_->GetAnimationType(); };
30 :
31 0 : int GetSpeed() const { return speed_; }
32 0 : void SetSpeed(int new_speed) { speed_ = new_speed; }
33 :
34 0 : unsigned int GetFrame() const { return frame_; }
35 0 : void SetFrame(unsigned int new_frame) { frame_ = new_frame; }
36 0 : void SetNextFrame() { frame_++; }
37 :
38 0 : int GetCount() const { return count_; }
39 : void SetCount(int new_count) { count_ = new_count; }
40 :
41 : // This method calls a shooting event to spawn a projectile for the current primary weapon
42 : // if a player presses the fire button. It has a separate method for that because it's a shared
43 : // functionality between many animation types and players are allowed to shoot during
44 : // animations. That's why we need to handle it in a special way.
45 : void TryToShoot(Soldier& soldier, const PhysicsEvents& physics_events) const;
46 :
47 : // This method calls a flag throwing event.It has a separate method for that because it's a
48 : // shared functionality between many animation types and players are allowed to shoot during
49 : // animations. That's why we need to handle it in a special way.
50 : void TryToThrowFlags(Soldier& soldier, const PhysicsEvents& physics_events) const;
51 :
52 : virtual void Enter(Soldier& soldier);
53 : virtual std::optional<std::shared_ptr<AnimationState>> HandleInput(Soldier& soldier) = 0;
54 : virtual void Update(Soldier& soldier, const PhysicsEvents& physics_events);
55 : virtual void Exit(Soldier& soldier, const PhysicsEvents& physics_events);
56 :
57 : protected:
58 : // This method should be overwritten by child classes to determine whether it's possible to
59 : // shoot during the current animation state
60 : virtual bool IsSoldierShootingPossible(const Soldier& soldier) const;
61 :
62 : // This method should be overwritten by child classes to determine whether it's possible to
63 : // throw all the flags during the current animation state
64 : virtual bool IsSoldierFlagThrowingPossible(const Soldier& soldier) const;
65 :
66 : std::shared_ptr<const AnimationData> animation_data_;
67 :
68 : int speed_;
69 : int count_;
70 : unsigned int frame_;
71 : };
72 : } // namespace Soldank
73 :
74 : #endif
|