diff --git a/dinkyecs.hpp b/dinkyecs.hpp index 31ffaa4..f5630e5 100644 --- a/dinkyecs.hpp +++ b/dinkyecs.hpp @@ -26,6 +26,12 @@ namespace DinkyECS { return $components[std::type_index(typeid(Comp))]; } + template + void remove(Entity ent) { + EntityMap &map = entity_map_for(); + map.erase(ent); + } + template void set(Comp val) { $facts[std::type_index(typeid(Comp))] = val; @@ -61,12 +67,6 @@ namespace DinkyECS { } } - template - void remove(Entity ent) { - EntityMap &map = entity_map_for(); - map.erase(ent); - } - template void system(std::function cb) { EntityMap &map_a = entity_map_for(); diff --git a/gui.cpp b/gui.cpp index 7936825..f72d166 100644 --- a/gui.cpp +++ b/gui.cpp @@ -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 sprite.setPosition({x+width_delta, y+height_delta}); + // get the entity combat and make them light gray if dead if(tile == L'█') { sprite.setColor(sf::Color(80,80,80)); } else if(tile == L'☺') { diff --git a/status.txt b/status.txt index 7b74f82..fad31de 100644 --- a/status.txt +++ b/status.txt @@ -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? * 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. diff --git a/systems.cpp b/systems.cpp index b8e503e..f1f0871 100644 --- a/systems.cpp +++ b/systems.cpp @@ -66,7 +66,7 @@ void System::motion(DinkyECS::World &world, Map &game_map) { void System::combat(DinkyECS::World &world, Player &player) { - const auto& collider = world.get(); + auto& collider = world.get(); const auto& player_position = world.component(player.entity); auto& player_combat = world.component(player.entity); auto& log = world.get(); @@ -76,14 +76,26 @@ void System::combat(DinkyECS::World &world, Player &player) { if(found) { for(auto entity : nearby) { - int attack = Random::uniform(0,1); - if(attack) { - const auto& enemy_dmg = world.component(entity); - int dmg = Random::uniform(1, enemy_dmg.damage); - player_combat.hp -= dmg; - log.log(format("HIT! You took {} damage.", dmg)); + auto& enemy_combat = world.component(entity); + int player_dmg = Random::uniform(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(entity); + collider.remove(enemy_position.location); + world.remove(entity); } else { - log.log("You dodged! Run!"); + int attack = Random::uniform(0,1); + if(attack) { + int dmg = Random::uniform(1, enemy_combat.damage); + player_combat.hp -= dmg; + log.log(format("HIT! You took {} damage.", dmg)); + } else { + log.log("You dodged! Run!"); + } } } }