Very basic collision and combat to work out the idea and a logging system on the left.
This commit is contained in:
parent
98993481b0
commit
dbc2a10933
5 changed files with 57 additions and 13 deletions
25
systems.cpp
25
systems.cpp
|
@ -1,6 +1,8 @@
|
|||
#include "systems.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include "rand.hpp"
|
||||
|
||||
using std::string;
|
||||
using namespace fmt;
|
||||
|
@ -33,8 +35,9 @@ void System::motion(DinkyECS::World &world, Map &game_map) {
|
|||
};
|
||||
motion = {0,0}; // clear it after getting it
|
||||
|
||||
// avoid colision, but could this be a different system?
|
||||
if(game_map.inmap(move_to.x, move_to.y) && !game_map.iswall(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))
|
||||
{
|
||||
position.location = move_to;
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +47,22 @@ void System::motion(DinkyECS::World &world, Map &game_map) {
|
|||
|
||||
void System::combat(DinkyECS::World &world, Player &player) {
|
||||
const auto& player_position = world.component<Position>(player.entity);
|
||||
auto& player_combat = world.component<Combat>(player.entity);
|
||||
auto& log = world.get<ActionLog>();
|
||||
|
||||
world.system<Position, Combat>([&](const auto &ent, auto &pos, auto &combat) {
|
||||
if(ent != player.entity && pos.location.x == player_position.location.x &&
|
||||
pos.location.y == player_position.location.y)
|
||||
{
|
||||
// need to sort out combat here
|
||||
if(ent != player.entity) {
|
||||
int dx = std::abs(int(pos.location.x) - int(player_position.location.x));
|
||||
int dy = std::abs(int(pos.location.y) - int(player_position.location.y));
|
||||
|
||||
if(dx <= 1 && dy <= 1) {
|
||||
if(player_combat.hp > -1) {
|
||||
int dmg = Random::uniform<int>(1, combat.damage);
|
||||
player_combat.hp -= dmg;
|
||||
|
||||
log.log(format("HIT! You took {} damage.", dmg));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue