Implement a simple combat system and killing off enemies. See status for next steps.

main
Zed A. Shaw 4 weeks ago
parent 62562faad3
commit 4162287841
  1. 12
      dinkyecs.hpp
  2. 1
      gui.cpp
  3. 4
      status.txt
  4. 18
      systems.cpp

@ -26,6 +26,12 @@ namespace DinkyECS {
return $components[std::type_index(typeid(Comp))]; return $components[std::type_index(typeid(Comp))];
} }
template <typename Comp>
void remove(Entity ent) {
EntityMap &map = entity_map_for<Comp>();
map.erase(ent);
}
template <typename Comp> template <typename Comp>
void set(Comp val) { void set(Comp val) {
$facts[std::type_index(typeid(Comp))] = val; $facts[std::type_index(typeid(Comp))] = val;
@ -61,12 +67,6 @@ namespace DinkyECS {
} }
} }
template<typename Comp>
void remove(Entity ent) {
EntityMap &map = entity_map_for<Comp>();
map.erase(ent);
}
template<typename CompA, typename CompB> template<typename CompA, typename CompB>
void system(std::function<void(const Entity&, CompA&, CompB&)> cb) { void system(std::function<void(const Entity&, CompA&, CompB&)> cb) {
EntityMap &map_a = entity_map_for<CompA>(); EntityMap &map_a = entity_map_for<CompA>();

@ -226,6 +226,7 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
// TODO: need to center it inside the bg_sprite // TODO: need to center it inside the bg_sprite
sprite.setPosition({x+width_delta, y+height_delta}); sprite.setPosition({x+width_delta, y+height_delta});
// get the entity combat and make them light gray if dead
if(tile == L'') { if(tile == L'') {
sprite.setColor(sf::Color(80,80,80)); sprite.setColor(sf::Color(80,80,80));
} else if(tile == L'') { } else if(tile == L'') {

@ -2,6 +2,8 @@ TODO:
* Write a test that generates a ton of maps then confirms there's a path from one room to every other room? * Write a test that generates a ton of maps then confirms there's a path from one room to every other room?
* Lua integration? * Lua integration?
* Text is not actually cleared when rendered either in FTXUI or SFML.
* Combat system and simple loot system.
* Actually render FTXUI ansi output instead of the gui.cpp hack.
* Remove entity from worl, _or_ mark them dead, switch their icon, and make them an entity the player walks over?
* Bring back sounds, check out SoLoud. * Bring back sounds, check out SoLoud.

@ -66,7 +66,7 @@ void System::motion(DinkyECS::World &world, Map &game_map) {
void System::combat(DinkyECS::World &world, Player &player) { void System::combat(DinkyECS::World &world, Player &player) {
const auto& collider = world.get<spatial_map>(); auto& collider = world.get<spatial_map>();
const auto& player_position = world.component<Position>(player.entity); const auto& player_position = world.component<Position>(player.entity);
auto& player_combat = world.component<Combat>(player.entity); auto& player_combat = world.component<Combat>(player.entity);
auto& log = world.get<ActionLog>(); auto& log = world.get<ActionLog>();
@ -76,10 +76,21 @@ void System::combat(DinkyECS::World &world, Player &player) {
if(found) { if(found) {
for(auto entity : nearby) { for(auto entity : nearby) {
auto& enemy_combat = world.component<Combat>(entity);
int player_dmg = Random::uniform<int>(1, enemy_combat.damage);
enemy_combat.hp -= player_dmg;
log.log(format("YOU HIT {} damage! Enemy has {} HP left.",
player_dmg, enemy_combat.hp));
if(enemy_combat.hp <= 0) {
log.log("--- ENEMY DEAD!---");
auto enemy_position = world.component<Position>(entity);
collider.remove(enemy_position.location);
world.remove<Motion>(entity);
} else {
int attack = Random::uniform<int>(0,1); int attack = Random::uniform<int>(0,1);
if(attack) { if(attack) {
const auto& enemy_dmg = world.component<Combat>(entity); int dmg = Random::uniform<int>(1, enemy_combat.damage);
int dmg = Random::uniform<int>(1, enemy_dmg.damage);
player_combat.hp -= dmg; player_combat.hp -= dmg;
log.log(format("HIT! You took {} damage.", dmg)); log.log(format("HIT! You took {} damage.", dmg));
} else { } else {
@ -87,6 +98,7 @@ void System::combat(DinkyECS::World &world, Player &player) {
} }
} }
} }
}
}; };
void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) { void System::draw_entities(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) {

Loading…
Cancel
Save