Basic combat system prototype works, but needs more GUI love to really work in the game.
This commit is contained in:
parent
bfd2718cc9
commit
f8dd5d816f
3 changed files with 35 additions and 0 deletions
28
systems.cpp
28
systems.cpp
|
@ -130,6 +130,34 @@ void System::death(GameLevel &level) {
|
|||
});
|
||||
}
|
||||
|
||||
void System::combat(GameLevel &level) {
|
||||
auto &collider = *level.collision;
|
||||
auto &world = *level.world;
|
||||
auto player = world.get_the<Player>();
|
||||
|
||||
const auto& player_position = world.get<Position>(player.entity);
|
||||
auto& player_combat = world.get<Combat>(player.entity);
|
||||
|
||||
// this is guaranteed to not return the given position
|
||||
auto [found, nearby] = collider.neighbors(player_position.location);
|
||||
|
||||
if(found) {
|
||||
for(auto entity : nearby) {
|
||||
if(world.has<Combat>(entity)) {
|
||||
auto& enemy_combat = world.get<Combat>(entity);
|
||||
|
||||
Events::Combat result {
|
||||
player_combat.attack(enemy_combat),
|
||||
enemy_combat.attack(player_combat)
|
||||
};
|
||||
|
||||
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void System::collision(GameLevel &level) {
|
||||
auto &collider = *level.collision;
|
||||
auto &world = *level.world;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue