]> git.localhorst.tv Git - orbi.git/blobdiff - src/app/Controller.cpp
simple controller
[orbi.git] / src / app / Controller.cpp
diff --git a/src/app/Controller.cpp b/src/app/Controller.cpp
new file mode 100644 (file)
index 0000000..88dd5eb
--- /dev/null
@@ -0,0 +1,65 @@
+#include "Controller.h"
+
+#include "../world/Entity.h"
+#include "../graphics/const.h"
+
+#include <algorithm>
+
+
+namespace orbi {
+
+Controller::Controller(Entity *ent)
+: e(ent)
+, moving(0)
+, moveAcc(3.5)
+, moveTerm(5)
+, jumping(false)
+, jumpVel(-5) {
+
+}
+
+void Controller::Update(float delta) {
+       if (!e) return;
+
+       if (moving) {
+               if (std::abs(e->acc.x) < moveTerm) {
+                       e->acc.x = sigma(moving) * moveAcc;
+               } else {
+                       e->acc.x = 0;
+               }
+       } else {
+               e->acc.x = sigma(e->vel.x) * -moveAcc;
+       }
+
+       if (jumping && e->onGround) {
+               e->vel.y += jumpVel;
+               jumping = false;
+       }
+}
+
+
+void Controller::MoveLeft() {
+       moving -= 1;
+}
+
+void Controller::StopLeft() {
+       moving += 1;
+}
+
+void Controller::MoveRight() {
+       moving += 1;
+}
+
+void Controller::StopRight() {
+       moving -= 1;
+}
+
+void Controller::StartJump() {
+       jumping = true;
+}
+
+void Controller::StopJump() {
+       jumping = false;
+}
+
+}