Give the player first move advantage, but maybe this should be a setting on motion so that some enemies can beat the player.
This commit is contained in:
parent
5a123ae74c
commit
62562faad3
1 changed files with 21 additions and 13 deletions
20
systems.cpp
20
systems.cpp
|
@ -33,12 +33,7 @@ void System::init_positions(DinkyECS::World &world) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::motion(DinkyECS::World &world, Map &game_map) {
|
inline void move_entity(spatial_map &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) {
|
||||||
auto &collider = world.get<spatial_map>();
|
|
||||||
|
|
||||||
world.system<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
|
|
||||||
// don't process entities that don't move
|
|
||||||
if(motion.dx != 0 || motion.dy != 0) {
|
|
||||||
Point move_to = {
|
Point move_to = {
|
||||||
position.location.x + motion.dx,
|
position.location.x + motion.dx,
|
||||||
position.location.y + motion.dy
|
position.location.y + motion.dy
|
||||||
|
@ -52,6 +47,19 @@ void System::motion(DinkyECS::World &world, Map &game_map) {
|
||||||
collider.move(position.location, move_to, ent);
|
collider.move(position.location, move_to, ent);
|
||||||
position.location = move_to;
|
position.location = move_to;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void System::motion(DinkyECS::World &world, Map &game_map) {
|
||||||
|
auto &collider = world.get<spatial_map>();
|
||||||
|
auto &player = world.get<Player>();
|
||||||
|
auto &player_position = world.component<Position>(player.entity);
|
||||||
|
auto &player_motion = world.component<Motion>(player.entity);
|
||||||
|
move_entity(collider, game_map, player_position, player_motion, player.entity);
|
||||||
|
|
||||||
|
world.system<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
|
||||||
|
// don't process entities that don't move
|
||||||
|
if(motion.dx != 0 || motion.dy != 0) {
|
||||||
|
move_entity(collider, game_map, position, motion, ent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue