summary refs log tree commit diff stats
path: root/src/components/ponderable.h
blob: da509a28c5b0a1aa3273381529d50e25013dfc3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef TANGIBLE_H_746DB3EE
#define TANGIBLE_H_746DB3EE

#include "component.h"
#include <functional>
#include <array>

class Game;

class PonderableComponent : public Component {
public:

  enum class BodyType {
    vacuumed,
    freefalling
  };

  enum class ColliderType {
    player,
    event
  };

  static const size_t COLLIDER_TYPES = 2;

  PonderableComponent(
    BodyType bodyType,
    ColliderType colliderType) :
      bodyType_(bodyType),
      colliderType_(colliderType)
  {
  }

  using event_callback_type = std::function<void(Game& game)>;

  inline BodyType getBodyType() const
  {
    return bodyType_;
  }

  inline ColliderType getColliderType() const
  {
    return colliderType_;
  }

  inline double getVelocityX() const
  {
    return velX_;
  }

  inline void setVelocityX(double v)
  {
    velX_ = v;
  }

  inline double getVelocityY() const
  {
    return velY_;
  }

  inline void setVelocityY(double v)
  {
    velY_ = v;
  }

  inline double getAccelX() const
  {
    return accelX_;
  }

  inline void setAccelX(double v)
  {
    accelX_ = v;
  }

  inline double getAccelY() const
  {
    return accelY_;
  }

  inline void setAccelY(double v)
  {
    accelY_ = v;
  }

  inline bool isGrounded() const
  {
    return grounded_;
  }

  inline void setGrounded(bool v)
  {
    grounded_ = v;
  }

  inline bool isFrozen() const
  {
    return frozen_;
  }

  inline void setFrozen(bool v)
  {
    frozen_ = v;
  }

  inline bool isCollidable() const
  {
    return collidable_;
  }

  inline void setCollidable(bool v)
  {
    collidable_ = v;
  }

  inline const event_callback_type& getEventCallback(ColliderType v) const
  {
    return eventCallbacks_[static_cast<size_t>(v)];
  }

  inline void setEventCallback(ColliderType v, event_callback_type callback)
  {
    eventCallbacks_[static_cast<size_t>(v)] = std::move(callback);
  }

private:

  double velX_ = 0.0;
  double velY_ = 0.0;
  double accelX_ = 0.0;
  double accelY_ = 0.0;
  BodyType bodyType_;
  ColliderType colliderType_;
  bool grounded_ = false;
  bool frozen_ = false;
  bool collidable_ = true;
  std::array<event_callback_type, COLLIDER_TYPES> eventCallbacks_;
};

#endif /* end of include guard: TANGIBLE_H_746DB3EE */