1 class InputComponent
2 {
3
4 public:
5 void update(Bjorn& bjorn)
6 {
7 switch (Controller::getJoystickDirection())
8 {
9 case DIR_LEFT:
10 bjorn.velocity -= WALK_ACCELERATION;
11 break;
12
13 case DIR_RIGHT:
14 bjorn.velocity += WALK_ACCELERATION;
15 break;
16 }
17 }
18
19 private:
20 static const int WALK_ACCELERATION = 1;
21
22 };
23
24 class PhysicsComponent
25 {
26
27 public:
28 void update(Bjorn& bjorn, World& world)
29 {
30 bjorn.x += bjorn.velocity;
31 world.resolveCollision(volume_,
32 bjorn.x, bjorn.y, bjorn.velocity);
33 }
34
35 private:
36 Volume volume_;
37
38 };
39
40 class GraphicsComponent
41 {
42
43 public:
44 void update(Bjorn& bjorn, Graphics& graphics)
45 {
46 Sprite* sprite = &spriteStand_;
47 if (bjorn.velocity < 0)
48 {
49 sprite = &spriteWalkLeft_;
50 }
51 else if (bjorn.velocity > 0)
52 {
53 sprite = &spriteWalkRight_;
54 }
55
56 graphics.draw(*sprite, bjorn.x, bjorn.y);
57 }
58
59 private:
60 Sprite spriteStand_;
61 Sprite spriteWalkLeft_;
62 Sprite spriteWalkRight_;
63
64 };