diff options
Diffstat (limited to 'src/components/ponderable.h')
-rw-r--r-- | src/components/ponderable.h | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 78af25f..da509a2 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h | |||
@@ -2,22 +2,44 @@ | |||
2 | #define TANGIBLE_H_746DB3EE | 2 | #define TANGIBLE_H_746DB3EE |
3 | 3 | ||
4 | #include "component.h" | 4 | #include "component.h" |
5 | #include <functional> | ||
6 | #include <array> | ||
7 | |||
8 | class Game; | ||
5 | 9 | ||
6 | class PonderableComponent : public Component { | 10 | class PonderableComponent : public Component { |
7 | public: | 11 | public: |
8 | 12 | ||
9 | enum class Type { | 13 | enum class BodyType { |
10 | vacuumed, | 14 | vacuumed, |
11 | freefalling | 15 | freefalling |
12 | }; | 16 | }; |
13 | 17 | ||
14 | PonderableComponent(Type type) : type_(type) | 18 | enum class ColliderType { |
19 | player, | ||
20 | event | ||
21 | }; | ||
22 | |||
23 | static const size_t COLLIDER_TYPES = 2; | ||
24 | |||
25 | PonderableComponent( | ||
26 | BodyType bodyType, | ||
27 | ColliderType colliderType) : | ||
28 | bodyType_(bodyType), | ||
29 | colliderType_(colliderType) | ||
30 | { | ||
31 | } | ||
32 | |||
33 | using event_callback_type = std::function<void(Game& game)>; | ||
34 | |||
35 | inline BodyType getBodyType() const | ||
15 | { | 36 | { |
37 | return bodyType_; | ||
16 | } | 38 | } |
17 | 39 | ||
18 | inline Type getType() const | 40 | inline ColliderType getColliderType() const |
19 | { | 41 | { |
20 | return type_; | 42 | return colliderType_; |
21 | } | 43 | } |
22 | 44 | ||
23 | inline double getVelocityX() const | 45 | inline double getVelocityX() const |
@@ -90,16 +112,28 @@ public: | |||
90 | collidable_ = v; | 112 | collidable_ = v; |
91 | } | 113 | } |
92 | 114 | ||
115 | inline const event_callback_type& getEventCallback(ColliderType v) const | ||
116 | { | ||
117 | return eventCallbacks_[static_cast<size_t>(v)]; | ||
118 | } | ||
119 | |||
120 | inline void setEventCallback(ColliderType v, event_callback_type callback) | ||
121 | { | ||
122 | eventCallbacks_[static_cast<size_t>(v)] = std::move(callback); | ||
123 | } | ||
124 | |||
93 | private: | 125 | private: |
94 | 126 | ||
95 | double velX_ = 0.0; | 127 | double velX_ = 0.0; |
96 | double velY_ = 0.0; | 128 | double velY_ = 0.0; |
97 | double accelX_ = 0.0; | 129 | double accelX_ = 0.0; |
98 | double accelY_ = 0.0; | 130 | double accelY_ = 0.0; |
99 | Type type_ = Type::vacuumed; | 131 | BodyType bodyType_; |
132 | ColliderType colliderType_; | ||
100 | bool grounded_ = false; | 133 | bool grounded_ = false; |
101 | bool frozen_ = false; | 134 | bool frozen_ = false; |
102 | bool collidable_ = true; | 135 | bool collidable_ = true; |
136 | std::array<event_callback_type, COLLIDER_TYPES> eventCallbacks_; | ||
103 | }; | 137 | }; |
104 | 138 | ||
105 | #endif /* end of include guard: TANGIBLE_H_746DB3EE */ | 139 | #endif /* end of include guard: TANGIBLE_H_746DB3EE */ |