|
|
@ -7,6 +7,7 @@ |
|
|
|
#include "events.hpp" |
|
|
|
#include "events.hpp" |
|
|
|
#include "ftxui/screen/color.hpp" |
|
|
|
#include "ftxui/screen/color.hpp" |
|
|
|
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor |
|
|
|
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor |
|
|
|
|
|
|
|
#include "dbc.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
using std::string; |
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
@ -40,9 +41,13 @@ void System::init_positions(DinkyECS::World &world) { |
|
|
|
collider.insert(pos.location, ent); |
|
|
|
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 = { |
|
|
|
Point move_to = { |
|
|
|
position.location.x + motion.dx, |
|
|
|
position.location.x + motion.dx, |
|
|
|
position.location.y + motion.dy |
|
|
|
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
|
|
|
|
motion = {0,0}; // clear it after getting it
|
|
|
|
|
|
|
|
|
|
|
|
if(game_map.inmap(move_to.x, move_to.y) && |
|
|
|
if(game_map.inmap(move_to.x, move_to.y) && |
|
|
|
!game_map.iswall(move_to.x, move_to.y) && |
|
|
|
!game_map.iswall(move_to.x, move_to.y)) |
|
|
|
!collider.occupied(move_to)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
collider.move(position.location, move_to, ent); |
|
|
|
if(collider.occupied(move_to)) { |
|
|
|
position.location = 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) { |
|
|
|
void System::motion(DinkyECS::World &world, Map &game_map) { |
|
|
|
auto &collider = world.get_the<spatial_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) { |
|
|
|
world.query<Position, Motion>([&](const auto &ent, auto &position, auto &motion) { |
|
|
|
// don't process entities that don't move
|
|
|
|
// don't process entities that don't move
|
|
|
|
if(motion.dx != 0 || motion.dy != 0) { |
|
|
|
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,25 +110,31 @@ void System::combat(DinkyECS::World &world, Player &player) { |
|
|
|
|
|
|
|
|
|
|
|
if(found) { |
|
|
|
if(found) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
for(auto entity : nearby) { |
|
|
|
auto& enemy_combat = world.get<Combat>(entity); |
|
|
|
if(world.has<Combat>(entity)) { |
|
|
|
int player_dmg = player_combat.attack(enemy_combat); |
|
|
|
auto& enemy_combat = world.get<Combat>(entity); |
|
|
|
|
|
|
|
int player_dmg = player_combat.attack(enemy_combat); |
|
|
|
|
|
|
|
|
|
|
|
if(player_dmg > 0) { |
|
|
|
if(player_dmg > 0) { |
|
|
|
world.send<Events::GUI>(Events::GUI::HIT, entity); |
|
|
|
world.send<Events::GUI>(Events::GUI::HIT, entity); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
world.send<Events::GUI>(Events::GUI::MISS, entity); |
|
|
|
world.send<Events::GUI>(Events::GUI::MISS, entity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(enemy_combat.hp > 0) { |
|
|
|
if(enemy_combat.hp > 0) { |
|
|
|
int enemy_dmg = enemy_combat.attack(player_combat); |
|
|
|
int enemy_dmg = enemy_combat.attack(player_combat); |
|
|
|
|
|
|
|
|
|
|
|
if(enemy_dmg > 0) { |
|
|
|
if(enemy_dmg > 0) { |
|
|
|
world.send<Events::GUI>(Events::GUI::HIT, player.entity); |
|
|
|
world.send<Events::GUI>(Events::GUI::HIT, player.entity); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
world.send<Events::GUI>(Events::GUI::MISS, player.entity); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
world.send<Events::GUI>(Events::GUI::MISS, player.entity); |
|
|
|
world.send<Events::GUI>(Events::GUI::DEAD, entity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if(world.has<Loot>(entity)) { |
|
|
|
|
|
|
|
println("YOU FOUND LOOT"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
world.send<Events::GUI>(Events::GUI::DEAD, entity); |
|
|
|
println("UNKNOWN COLLISION TYPE {}", entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|