]> git.localhorst.tv Git - orbi.git/blob - src/app/Controller.cpp
orientation for entities
[orbi.git] / src / app / Controller.cpp
1 #include "Controller.h"
2
3 #include "../world/Entity.h"
4 #include "../graphics/const.h"
5
6 #include <algorithm>
7
8
9 namespace orbi {
10
11 Controller::Controller(Entity *ent)
12 : e(ent)
13 , moving(0)
14 , moveAcc(3.5)
15 , moveTerm(5)
16 , jumping(false)
17 , jumpVel(-6) {
18
19 }
20
21 void Controller::Update(float delta) {
22         if (!e) return;
23
24         if (moving) {
25                 if (std::abs(e->acc.x) < moveTerm) {
26                         e->acc.x = sigma(moving) * moveAcc;
27                 } else {
28                         e->acc.x = 0;
29                 }
30         } else {
31                 e->acc.x = sigma(e->vel.x) * -moveAcc;
32         }
33
34         if (jumping && e->onGround) {
35                 e->vel.y += jumpVel;
36                 jumping = false;
37         }
38 }
39
40
41 void Controller::MoveLeft() {
42         moving -= 1;
43         e->orient = Entity::LOOKS_LEFT;
44 }
45
46 void Controller::StopLeft() {
47         moving += 1;
48 }
49
50 void Controller::MoveRight() {
51         moving += 1;
52         e->orient = Entity::LOOKS_RIGHT;
53 }
54
55 void Controller::StopRight() {
56         moving -= 1;
57 }
58
59 void Controller::StartJump() {
60         jumping = true;
61 }
62
63 void Controller::StopJump() {
64         jumping = false;
65 }
66
67 }