diff --git a/gui.cpp b/gui.cpp index 9667ebc..3f2f185 100644 --- a/gui.cpp +++ b/gui.cpp @@ -96,6 +96,7 @@ namespace gui { // just do 10 ticks if($rotation_count % 10 == 0) { + System::combat($level); run_systems(); $rotation = -10.0f; state(State::IDLE); @@ -182,6 +183,10 @@ namespace gui { $camera.plan_rotate($rayview, -1); state(State::COMBAT_ROTATE); break; + case QUIT: + $window.close(); + state(State::END); + return; default: break; } diff --git a/systems.cpp b/systems.cpp index d178e52..6293c53 100644 --- a/systems.cpp +++ b/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(); + + const auto& player_position = world.get(player.entity); + auto& player_combat = world.get(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(entity)) { + auto& enemy_combat = world.get(entity); + + Events::Combat result { + player_combat.attack(enemy_combat), + enemy_combat.attack(player_combat) + }; + + world.send(Events::GUI::COMBAT, entity, result); + } + } + } +} + + void System::collision(GameLevel &level) { auto &collider = *level.collision; auto &world = *level.world; diff --git a/systems.hpp b/systems.hpp index 9d51547..d0e4460 100644 --- a/systems.hpp +++ b/systems.hpp @@ -18,4 +18,6 @@ namespace System { void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); void plan_motion(DinkyECS::World& world, Point move_to); void draw_entities(DinkyECS::World &world, Map &map, const Matrix &lights, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y); + + void combat(GameLevel &level); }