|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
#include "events.hpp" |
|
|
|
|
#include "ftxui/screen/color.hpp" |
|
|
|
|
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor |
|
|
|
|
#include "dbc.hpp" |
|
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
|
using namespace fmt; |
|
|
|
@ -40,9 +41,13 @@ void System::init_positions(DinkyECS::World &world) { |
|
|
|
|
collider.insert(pos.location, ent); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
world.query<Position, Loot>([&](const auto &ent, auto &pos, auto &loot) { |
|
|
|
|
collider.insert(pos.location, ent); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void move_entity(spatial_map &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) { |
|
|
|
|
inline bool move_entity(spatial_map &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) { |
|
|
|
|
Point move_to = { |
|
|
|
|
position.location.x + motion.dx, |
|
|
|
|
position.location.y + motion.dy |
|
|
|
@ -50,25 +55,31 @@ inline void move_entity(spatial_map &collider, Map &game_map, Position &position |
|
|
|
|
motion = {0,0}; // clear it after getting it
|
|
|
|
|
|
|
|
|
|
if(game_map.inmap(move_to.x, move_to.y) && |
|
|
|
|
!game_map.iswall(move_to.x, move_to.y) && |
|
|
|
|
!collider.occupied(move_to)) |
|
|
|
|
!game_map.iswall(move_to.x, move_to.y)) |
|
|
|
|
{ |
|
|
|
|
if(collider.occupied(move_to)) { |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
collider.move(position.location, move_to, ent); |
|
|
|
|
position.location = move_to; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void System::motion(DinkyECS::World &world, Map &game_map) { |
|
|
|
|
auto &collider = world.get_the<spatial_map>(); |
|
|
|
|
auto &player = world.get_the<Player>(); |
|
|
|
|
auto &player_position = world.get<Position>(player.entity); |
|
|
|
|
auto &player_motion = world.get<Motion>(player.entity); |
|
|
|
|
move_entity(collider, game_map, player_position, player_motion, player.entity); |
|
|
|
|
|
|
|
|
|
world.query<Position, Motion>([&](const auto &ent, auto &position, auto &motion) { |
|
|
|
|
// don't process entities that don't move
|
|
|
|
|
if(motion.dx != 0 || motion.dy != 0) { |
|
|
|
|
move_entity(collider, game_map, position, motion, ent); |
|
|
|
|
// if there's a collision
|
|
|
|
|
if(move_entity(collider, game_map, position, motion, ent)) { |
|
|
|
|
// send a collision event?
|
|
|
|
|
println("hit it!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -99,6 +110,7 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
|
|
|
|
|
|
if(found) { |
|
|
|
|
for(auto entity : nearby) { |
|
|
|
|
if(world.has<Combat>(entity)) { |
|
|
|
|
auto& enemy_combat = world.get<Combat>(entity); |
|
|
|
|
int player_dmg = player_combat.attack(enemy_combat); |
|
|
|
|
|
|
|
|
@ -119,6 +131,11 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
|
} else { |
|
|
|
|
world.send<Events::GUI>(Events::GUI::DEAD, entity); |
|
|
|
|
} |
|
|
|
|
} else if(world.has<Loot>(entity)) { |
|
|
|
|
println("YOU FOUND LOOT"); |
|
|
|
|
} else { |
|
|
|
|
println("UNKNOWN COLLISION TYPE {}", entity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|