X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FController.cpp;fp=src%2Fapp%2FController.cpp;h=88dd5eb725f6a39c4c2ebc85da8f9dd766e2bd1b;hb=dbc08d84d9de1a77cba0dd97e4701f4ac99d056e;hp=0000000000000000000000000000000000000000;hpb=79a34acdc1beff20213f03c326a4aa03c5d47c92;p=orbi.git diff --git a/src/app/Controller.cpp b/src/app/Controller.cpp new file mode 100644 index 0000000..88dd5eb --- /dev/null +++ b/src/app/Controller.cpp @@ -0,0 +1,65 @@ +#include "Controller.h" + +#include "../world/Entity.h" +#include "../graphics/const.h" + +#include + + +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; +} + +}