Body UI and damage works better now.
This commit is contained in:
parent
f6c8163acd
commit
2dec4ec993
3 changed files with 22 additions and 12 deletions
|
|
@ -14,18 +14,25 @@ namespace components {
|
|||
}
|
||||
|
||||
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) {
|
||||
fmt::println("COUNT: {}", count);
|
||||
for(auto& [key, hp] : body_parts) {
|
||||
if(count > 0 && Random::uniform(0, 1) == 0) {
|
||||
fmt::println("HIT! name={} count={} dmg={} hp={}", key, count, my_dmg, hp);
|
||||
body_parts[key] = std::max(0, hp - my_dmg);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
// select a random body part
|
||||
size_t key = Random::uniform(size_t(0), part_names.size() - 1);
|
||||
const std::string& name = part_names[key];
|
||||
int hp = body_parts[name];
|
||||
|
||||
// catch this bug
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace gui {
|
|||
auto gui_id = $gui.entity(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, {}});
|
||||
}
|
||||
|
||||
|
|
@ -49,8 +50,10 @@ namespace gui {
|
|||
auto gui_id = $gui.entity(key);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue