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. 28
      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,14 +76,26 @@ void System::combat(DinkyECS::World &world, Player &player) {
if(found) { if(found) {
for(auto entity : nearby) { for(auto entity : nearby) {
int attack = Random::uniform<int>(0,1); auto& enemy_combat = world.component<Combat>(entity);
if(attack) { int player_dmg = Random::uniform<int>(1, enemy_combat.damage);
const auto& enemy_dmg = world.component<Combat>(entity); enemy_combat.hp -= player_dmg;
int dmg = Random::uniform<int>(1, enemy_dmg.damage); log.log(format("YOU HIT {} damage! Enemy has {} HP left.",
player_combat.hp -= dmg; player_dmg, enemy_combat.hp));
log.log(format("HIT! You took {} damage.", dmg));
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 { } else {
log.log("You dodged! Run!"); int attack = Random::uniform<int>(0,1);
if(attack) {
int dmg = Random::uniform<int>(1, enemy_combat.damage);
player_combat.hp -= dmg;
log.log(format("HIT! You took {} damage.", dmg));
} else {
log.log("You dodged! Run!");
}
} }
} }
} }

Loading…
Cancel
Save