System now controls the motion better since it's not GUIs job.

master
Zed A. Shaw 1 month ago
parent 1973a7a1df
commit e85b5d998b
  1. 10
      gui.cpp
  2. 8
      systems.cpp
  3. 1
      systems.hpp

@ -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<Player>();
auto& player_position = level.world->get<Position>(player.entity);
auto& motion = level.world->get<Motion>(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);
}
}

@ -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<Player>();
auto& player_position = world.get<Position>(player.entity);
auto& motion = world.get<Motion>(player.entity);
motion.dx = move_to.x - player_position.location.x;
motion.dy = move_to.y - player_position.location.y;
}

@ -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);
}

Loading…
Cancel
Save