Body UI and damage works better now.

This commit is contained in:
Zed A. Shaw 2026-04-01 12:13:48 -04:00
parent f6c8163acd
commit 2dec4ec993
3 changed files with 22 additions and 12 deletions

View file

@ -6,7 +6,7 @@
"foreground": "enemies/fg:player", "foreground": "enemies/fg:player",
"background": "color:transparent" "background": "color:transparent"
}, },
{"_type": "Combat", "max_hp": 50, "max_ap": 12, "ap_delta": 6, "damage": 20, "dead": false, {"_type": "Combat", "max_hp": 200, "max_ap": 12, "ap_delta": 6, "damage": 20, "dead": false,
"body_parts": { "body_parts": {
"head": 200, "head": 200,
"chest": 200, "chest": 200,

View file

@ -14,18 +14,25 @@ namespace components {
} }
void Combat::take_damage(int my_dmg) { void Combat::take_damage(int my_dmg) {
int count = Random::uniform(1, int(body_parts.size() - 1)); dbc::check(part_names.size() > 2, "Not enough body parts in part_names");
while(count > 0) { // select a random body part
fmt::println("COUNT: {}", count); size_t key = Random::uniform(size_t(0), part_names.size() - 1);
for(auto& [key, hp] : body_parts) { const std::string& name = part_names[key];
if(count > 0 && Random::uniform(0, 1) == 0) { int hp = body_parts[name];
fmt::println("HIT! name={} count={} dmg={} hp={}", key, count, my_dmg, hp);
body_parts[key] = std::max(0, hp - my_dmg); // catch this bug
count--; dbc::check(hp >= 0, "HP went negative");
}
} // don't hit dead parts
if(hp == 0) {
dbc::log("IT's zero.");
return;
} }
// don't go below 0
body_parts[name] = std::max(0, hp - my_dmg);
fmt::println("BODY PART {} was {} now {}", name, hp, body_parts[name]);
} }
bool Combat::less_than(int level) { bool Combat::less_than(int level) {

View file

@ -29,6 +29,7 @@ namespace gui {
auto gui_id = $gui.entity(name); auto gui_id = $gui.entity(name);
$gui.set<Text>(gui_id, {guecs::to_wstring(name)}); $gui.set<Text>(gui_id, {guecs::to_wstring(name)});
$gui.set<Rectangle>(gui_id, {1, {255, 0, 0, 255}});
$gui.set<Meter>(gui_id, {1.0f, THEME.DARK_MID, {}}); $gui.set<Meter>(gui_id, {1.0f, THEME.DARK_MID, {}});
} }
@ -49,8 +50,10 @@ namespace gui {
auto gui_id = $gui.entity(key); auto gui_id = $gui.entity(key);
if(auto meter = $gui.get_if<Meter>(gui_id)) { if(auto meter = $gui.get_if<Meter>(gui_id)) {
meter->percent = float(value) / 50.0; meter->percent = float(value) / float(player_combat.max_hp);
} }
$gui.show_text(key, fmt::format(L"{}: {}", guecs::to_wstring(key), value));
} }
} }