diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-11-25 19:29:33 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-11-25 19:29:33 -0500 |
commit | 6a55426a506c63eee7b8dea2967a6a5f5ecde038 (patch) | |
tree | 174aa1905db2831311e2bf961e83047f5ecb81bc /src/components.cpp | |
parent | 58b469223e6aef6323791141fb66d72d7d86d983 (diff) |
wandering
Diffstat (limited to 'src/components.cpp')
-rw-r--r-- | src/components.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/components.cpp b/src/components.cpp index 7c6091e..5b85f51 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -15,9 +15,25 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e { (void)ev; en.each<Position, Direction>([dt](entityx::Entity entity, Position &position, Direction &direction) { - (void)entity; position.x += direction.x * dt; position.y += direction.y * dt; + + if (entity.has_component<Sprite>()) { + auto& fl = entity.component<Sprite>()->faceLeft; + if (direction.x != 0) + fl = (direction.x < 0); + } + + if (entity.has_component<Wander>()) { + auto& countdown = entity.component<Wander>()->countdown; + + if (countdown > 0) { + countdown--; + } else { + countdown = 5000 + randGet() % 10 * 100; + direction.x = (randGet() % 3 - 1) * 0.02f; + } + } }); } @@ -26,7 +42,7 @@ void PhysicsSystem::update(entityx::EntityManager &en, entityx::EventManager &ev (void)ev; en.each<Direction, Physics>([dt](entityx::Entity entity, Direction &direction, Physics &physics) { (void)entity; - // TODO GET GRAVITY FROM WOLRD + // TODO GET GRAVITY FROM WORLD direction.y += physics.g * dt; }); } @@ -168,4 +184,3 @@ void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, (void)ev; (void)dt; } - |