]> git.localhorst.tv Git - space.git/blob - src/graphics/Moveable.h
grid view
[space.git] / src / graphics / Moveable.h
1 #ifndef SPACE_MOVEABLE_H_
2 #define SPACE_MOVEABLE_H_
3
4 #include "../math/Vector.h"
5
6
7 namespace space {
8
9 template<class Scalar>
10 class Moveable {
11
12 public:
13         Moveable(Vector<Scalar> pos, Scalar speed)
14         : dir(0, 0), pos(pos), speed(speed) { }
15
16 public:
17         const Vector<Scalar> &Pos() const { return pos; }
18         Vector<Scalar> Vel() const { return Vector<Scalar>(dir) * speed; }
19
20         void Update(Scalar delta) {
21                 pos += Vel() * delta;
22         }
23
24 public:
25         void MoveUp() { dir.y -= 1; }
26         void StopUp() { dir.y += 1; }
27         void MoveDown() { dir.y += 1; }
28         void StopDown() { dir.y -= 1; }
29         void MoveLeft() { dir.x -= 1; }
30         void StopLeft() { dir.x += 1; }
31         void MoveRight() { dir.x += 1; }
32         void StopRight() { dir.x -= 1; }
33
34 private:
35         Vector<int> dir;
36         Vector<Scalar> pos;
37         Scalar speed;
38
39 };
40
41 }
42
43 #endif