X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcontroller.cpp;h=fcdb407f43b047885881304584a88562113e580a;hb=46509f82dcea114b004c53a7f3a9608f2518077f;hp=b996f9e37a04c80301a5776c288b5af09202b38e;hpb=c3c5045f06327db2a3c97eae77a072bc06677286;p=blank.git diff --git a/src/controller.cpp b/src/controller.cpp index b996f9e..fcdb407 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -46,4 +46,54 @@ void FPSController::Update(int dt) { entity.Velocity(glm::rotateY(velocity, yaw)); } + +RandomWalk::RandomWalk(Entity &e) +: entity(e) +, time_left(0) { + +} + + +void RandomWalk::Update(int dt) { + time_left -= dt; + if (time_left > 0) return; + time_left += 2500 + (rand() % 5000); + + constexpr float move_vel = 0.0005f; + + glm::vec3 new_vel = entity.Velocity(); + + switch (rand() % 9) { + case 0: + new_vel.x = -move_vel; + break; + case 1: + new_vel.x = 0.0f; + break; + case 2: + new_vel.x = move_vel; + break; + case 3: + new_vel.y = -move_vel; + break; + case 4: + new_vel.y = 0.0f; + break; + case 5: + new_vel.y = move_vel; + break; + case 6: + new_vel.z = -move_vel; + break; + case 7: + new_vel.z = 0.0f; + break; + case 8: + new_vel.z = move_vel; + break; + } + + entity.Velocity(new_vel); +} + }