]> git.localhorst.tv Git - orbi.git/blob - src/app/Controller.cpp
some cleanup
[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 }
44
45 void Controller::StopLeft() {
46         moving += 1;
47 }
48
49 void Controller::MoveRight() {
50         moving += 1;
51 }
52
53 void Controller::StopRight() {
54         moving -= 1;
55 }
56
57 void Controller::StartJump() {
58         jumping = true;
59 }
60
61 void Controller::StopJump() {
62         jumping = false;
63 }
64
65 }