You can now take damage to your head.

This commit is contained in:
Zed A. Shaw 2026-03-29 23:54:21 -04:00
parent cbd4b858ac
commit d22eaa554d
7 changed files with 64 additions and 49 deletions

View file

@ -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);

View file

@ -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));