You can now take damage to your head.
This commit is contained in:
parent
cbd4b858ac
commit
d22eaa554d
7 changed files with 64 additions and 49 deletions
|
|
@ -8,9 +8,30 @@ namespace components {
|
|||
|
||||
if(attack) {
|
||||
my_dmg = Random::uniform<int>(1, damage);
|
||||
target.hp -= my_dmg;
|
||||
target.hit_limb(my_dmg);
|
||||
}
|
||||
|
||||
return my_dmg;
|
||||
}
|
||||
|
||||
void Combat::hit_limb(int my_dmg) {
|
||||
body_parts["head"] -= my_dmg;
|
||||
}
|
||||
|
||||
bool Combat::is_dead() {
|
||||
return body_parts["head"] < 0;
|
||||
}
|
||||
|
||||
bool Combat::almost_dead() {
|
||||
return body_parts["head"] < 20;
|
||||
}
|
||||
|
||||
bool Combat::can_heal() {
|
||||
return body_parts["head"] < 50;
|
||||
}
|
||||
|
||||
void Combat::apply_healing(Curative& cure) {
|
||||
int new_hp = body_parts["head"] + cure.hp;
|
||||
body_parts["head"] = std::min(new_hp, 50);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,10 +83,6 @@ namespace components {
|
|||
std::string ai_goal_name;
|
||||
};
|
||||
|
||||
struct Curative {
|
||||
int hp = 10;
|
||||
};
|
||||
|
||||
struct Sprite {
|
||||
string name;
|
||||
float scale;
|
||||
|
|
@ -106,12 +102,17 @@ namespace components {
|
|||
std::vector<std::array<std::string, 4>> beats;
|
||||
};
|
||||
|
||||
struct Curative {
|
||||
int hp = 10;
|
||||
};
|
||||
|
||||
struct Combat {
|
||||
int hp;
|
||||
int max_hp;
|
||||
int ap_delta;
|
||||
int max_ap;
|
||||
int damage;
|
||||
std::unordered_map<std::string, int> body_parts{
|
||||
{"head", 50},
|
||||
};
|
||||
|
||||
// everyone starts at 0 but ap_delta is added each round
|
||||
int ap = 0;
|
||||
|
|
@ -120,6 +121,11 @@ namespace components {
|
|||
bool dead = false;
|
||||
|
||||
int attack(Combat &target);
|
||||
void hit_limb(int my_dmg);
|
||||
bool is_dead();
|
||||
bool almost_dead();
|
||||
bool can_heal();
|
||||
void apply_healing(Curative& cure);
|
||||
};
|
||||
|
||||
struct LightSource {
|
||||
|
|
@ -156,7 +162,7 @@ namespace components {
|
|||
ENROLL_COMPONENT(EnemyConfig, ai_script, ai_start_name, ai_goal_name);
|
||||
ENROLL_COMPONENT(Personality, hearing_distance, tough);
|
||||
ENROLL_COMPONENT(Motion, dx, dy, random);
|
||||
ENROLL_COMPONENT(Combat, hp, max_hp, ap_delta, max_ap, damage, dead);
|
||||
ENROLL_COMPONENT(Combat, ap_delta, max_ap, damage, dead);
|
||||
ENROLL_COMPONENT(Device, config, events);
|
||||
ENROLL_COMPONENT(Storyboard, image, audio, layout, beats);
|
||||
ENROLL_COMPONENT(Sound, attack, death);
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ void System::death() {
|
|||
|
||||
world.query<Combat>([&](auto ent, auto &combat) {
|
||||
// bring out yer dead
|
||||
if(combat.hp <= 0 && !combat.dead) {
|
||||
if(combat.is_dead() && !combat.dead) {
|
||||
combat.dead = true;
|
||||
if(ent != player.entity) {
|
||||
// we won't change out the player's components later
|
||||
|
|
@ -196,7 +196,7 @@ void System::death() {
|
|||
}
|
||||
// we need to send this event for everything that dies
|
||||
world.send<game::Event>(game::Event::DEATH, ent, {});
|
||||
} else if(float(combat.hp) / float(combat.max_hp) < 0.5f) {
|
||||
} else if(combat.almost_dead()) {
|
||||
// if enemies are below 50% health they are marked with bad health
|
||||
if(world.has<ai::EntityAI>(ent)) {
|
||||
auto& enemy_ai = world.get<ai::EntityAI>(ent);
|
||||
|
|
@ -479,23 +479,14 @@ void System::use_item(const string& slot_name) {
|
|||
auto& inventory = world.get<inventory::Model>(level.player);
|
||||
auto& player_combat = world.get<Combat>(level.player);
|
||||
|
||||
if(player_combat.hp >= player_combat.max_hp) return;
|
||||
if(!player_combat.can_heal()) return;
|
||||
if(!inventory.has(slot_name)) return;
|
||||
|
||||
auto what = inventory.get(slot_name);
|
||||
|
||||
if(auto curative = world.get_if<Curative>(what)) {
|
||||
inventory.remove(what);
|
||||
|
||||
player_combat.hp += curative->hp;
|
||||
|
||||
if(player_combat.hp > player_combat.max_hp) {
|
||||
player_combat.hp = player_combat.max_hp;
|
||||
}
|
||||
|
||||
dbc::log($F("player health now {}",
|
||||
player_combat.hp));
|
||||
|
||||
player_combat.apply_healing(*curative);
|
||||
world.remove<Curative>(what);
|
||||
} else {
|
||||
dbc::log($F("no usable item at {}", what));
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ namespace gui {
|
|||
void BodyUI::init(size_t x, size_t y, size_t width, size_t height) {
|
||||
$gui.position(x, y, width, height);
|
||||
$gui.layout(
|
||||
"[body_head]"
|
||||
"[body_chest]"
|
||||
"[body_right_arm]"
|
||||
"[body_left_arm]"
|
||||
"[body_stomach]"
|
||||
"[body_left_leg]"
|
||||
"[body_right_leg]");
|
||||
"[head]"
|
||||
"[chest]"
|
||||
"[right_arm]"
|
||||
"[left_arm]"
|
||||
"[stomach]"
|
||||
"[left_leg]"
|
||||
"[right_leg]");
|
||||
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, });
|
||||
|
||||
|
|
@ -42,7 +42,16 @@ namespace gui {
|
|||
|
||||
void BodyUI::update() {
|
||||
auto world = GameDB::current_world();
|
||||
auto player = world->get_the<components::Player>();
|
||||
auto& player = world->get_the<components::Player>();
|
||||
auto& player_combat = world->get<components::Combat>(player.entity);
|
||||
|
||||
for(auto& [key, value] : player_combat.body_parts) {
|
||||
auto gui_id = $gui.entity(key);
|
||||
|
||||
if(auto meter = $gui.get_if<Meter>(gui_id)) {
|
||||
meter->percent = float(value) / 50.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BodyUI::render(sf::RenderWindow &window) {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ namespace gui {
|
|||
auto map = level.map;
|
||||
|
||||
std::wstring stats = $F(L"STATS\n"
|
||||
L"HP: {}\n"
|
||||
L"mean:{:>8.5}\n"
|
||||
L"sdev: {:>8.5}\n"
|
||||
L"min: {:>8.5}\n"
|
||||
|
|
@ -58,7 +57,7 @@ namespace gui {
|
|||
L"VSync? {}\n"
|
||||
L"FR Limit: {}\n"
|
||||
L"Debug? {}\n\n",
|
||||
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
|
||||
$stats.mean(), $stats.stddev(), $stats.min,
|
||||
$stats.max, $stats.n, level.index, map->width(), map->height(),
|
||||
VSYNC, FRAME_LIMIT, DEBUG_BUILD);
|
||||
|
||||
|
|
@ -74,9 +73,6 @@ namespace gui {
|
|||
if(active) {
|
||||
auto& level = GameDB::current_level();
|
||||
// it's on now, enable things
|
||||
auto player = level.world->get_the<components::Player>();
|
||||
auto& player_combat = level.world->get<components::Combat>(player.entity);
|
||||
player_combat.hp = player_combat.max_hp;
|
||||
$gui.show_text("debug_text", L"STATS");
|
||||
} else {
|
||||
// it's off now, close it
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue