diff --git a/ECS/Components/PathMove.h b/ECS/Components/PathMove.h index fec3f79..b22fb50 100644 --- a/ECS/Components/PathMove.h +++ b/ECS/Components/PathMove.h @@ -24,6 +24,8 @@ struct PathMove { float time_passed = 0.0; int current_point_index = 0; + int speed_addition = 0; // 0, -1 or 1 depending on whether the speed should stay, decrease or increase + Path path; Views views; }; diff --git a/ECS/Systems/PathMoveSystem.h b/ECS/Systems/PathMoveSystem.h index 3ef48c1..fa90ade 100644 --- a/ECS/Systems/PathMoveSystem.h +++ b/ECS/Systems/PathMoveSystem.h @@ -58,17 +58,17 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber { if (event.key == GLFW_KEY_W) { myWorld->each([&](Entity *ent, ComponentHandle pathmove) { if (event.action == GLFW_PRESS) { - // TODO: Velocity adder + pathmove->speed_addition += 1; } else if (event.action == GLFW_RELEASE) { - // TODO + pathmove->speed_addition -= 1; } }); } else if (event.key == GLFW_KEY_S) { myWorld->each([&](Entity *ent, ComponentHandle pathmove) { if (event.action == GLFW_PRESS) { - // TODO + pathmove->speed_addition -= 1; } else if (event.action == GLFW_RELEASE) { - // TODO + pathmove->speed_addition += 1; } }); } @@ -77,6 +77,10 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber { void tick(World *pWorld, float deltaTime) override { pWorld->each( [&](Entity *ent, ComponentHandle transform, ComponentHandle pathmove) { + // Handle change in speed + pathmove->speed += pathmove->speed_addition * deltaTime; + pathmove->speed = glm::clamp(pathmove->speed, 0.0, 10.0); + // Shorthand for the path (we'll use this a lot) PathMove::Path path = pathmove->path; diff --git a/main.cpp b/main.cpp index 27309e3..96f5634 100644 --- a/main.cpp +++ b/main.cpp @@ -88,13 +88,13 @@ int main() { Entity *player = world->create(); player->assign(); - player->assign(glm::vec3(2.f, 2.f, 2.f)); - player->assign(0.1); + //player->assign(glm::vec3(2.f, 2.f, 2.f)); + //player->assign(0.1); player->assign(70.0f, 1280, 720, 0.1f, 100.0f); - /*player->assign(10.0, PathMove::Path(std::vector{ + player->assign(3.0, PathMove::Path(std::vector{ glm::vec3(0.0, 2.0, 0.0), - glm::vec3(-2.0, 2.0, -1.0), - glm::vec3(-1.0, 2.0, -2.0), + glm::vec3(0.0, 2.0, -1.0), + glm::vec3(0.0, 2.0, -2.0), glm::vec3(4.0, 3.0, -3.0), glm::vec3(2.0, 2.0, -4.0), glm::vec3(1.0, 2.0, -4.0), @@ -109,7 +109,7 @@ int main() { glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)), glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f)) }) - );*/ + ); Entity *monkey = world->create(); monkey->assign();