Basic combat system prototype works, but needs more GUI love to really work in the game.

master
Zed A. Shaw 3 weeks ago
parent bfd2718cc9
commit f8dd5d816f
  1. 5
      gui.cpp
  2. 28
      systems.cpp
  3. 2
      systems.hpp

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

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

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

Loading…
Cancel
Save