]> git.localhorst.tv Git - space.git/blob - src/graphics/Moveable.h
move to SDL2
[space.git] / src / graphics / Moveable.h
1 #ifndef SPACE_MOVEABLE_H_
2 #define SPACE_MOVEABLE_H_
3
4 #include "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         void SetSpeed(float s) { speed = s; }
20
21         void Update(Scalar delta) {
22                 pos += Vel() * delta;
23         }
24
25 public:
26         void MoveUp() { dir.y -= 1; }
27         void StopUp() { dir.y += 1; }
28         void MoveDown() { dir.y += 1; }
29         void StopDown() { dir.y -= 1; }
30         void MoveLeft() { dir.x -= 1; }
31         void StopLeft() { dir.x += 1; }
32         void MoveRight() { dir.x += 1; }
33         void StopRight() { dir.x -= 1; }
34
35 private:
36         Vector<int> dir;
37         Vector<Scalar> pos;
38         Scalar speed;
39
40 };
41
42 }
43
44 #endif