diff --git a/gui.cpp b/gui.cpp index 200c0a2..7362927 100644 --- a/gui.cpp +++ b/gui.cpp @@ -44,16 +44,8 @@ namespace gui { void FSM::MOVING(Event ) { if($camera.play_move($rayview)) { - // really annoying but we have to figure out the motion factor then run the systems - auto& player = level.world->get_the(); - auto& player_position = level.world->get(player.entity); - auto& motion = level.world->get(player.entity); - Point move_to{size_t($camera.targetX), size_t($camera.targetY)}; - motion.dx = move_to.x - player_position.location.x; - motion.dy = move_to.y - player_position.location.y; - + System::plan_motion(*level.world, {size_t($camera.targetX), size_t($camera.targetY)}); run_systems(); - state(State::IDLE); } } diff --git a/systems.cpp b/systems.cpp index e65cea4..255fc70 100644 --- a/systems.cpp +++ b/systems.cpp @@ -213,3 +213,11 @@ void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::En println("entity {} INTERACTED WITH DEVICE {}", actor, item); } + +void System::plan_motion(DinkyECS::World& world, Point move_to) { + auto& player = world.get_the(); + auto& player_position = world.get(player.entity); + auto& motion = world.get(player.entity); + motion.dx = move_to.x - player_position.location.x; + motion.dy = move_to.y - player_position.location.y; +} diff --git a/systems.hpp b/systems.hpp index 282e439..f837e7c 100644 --- a/systems.hpp +++ b/systems.hpp @@ -15,4 +15,5 @@ namespace System { void init_positions(DinkyECS::World &world, SpatialMap &collider); void pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); + void plan_motion(DinkyECS::World& world, Point move_to); }