-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmortal.cpp
More file actions
49 lines (41 loc) · 1.14 KB
/
mortal.cpp
File metadata and controls
49 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "pch.h"
#include "main.hpp"
Mortal::Mortal(float maxHp, float def, const char *corpseName) : maxHp(maxHp), hp(maxHp), def(def), corpseName(corpseName) {}
float Mortal::takeDamage(std::shared_ptr<Ent>owner, float dmg) {
dmg -= def;
if (dmg > 0) {
hp -= dmg;
if (hp <= 0) {
die(owner);
}
}
else {
dmg = 0;
}
return dmg;
}
float Mortal::heal(float amount) {
hp += amount;
if (hp > maxHp) {
amount -= hp-maxHp;
hp = maxHp;
}
return amount;
}
void Mortal::die(std::shared_ptr<Ent> owner) {
owner->ch = '%';
owner->col = TCODColor::darkRed;
owner->name = corpseName;
owner->blocks = false;
}
pcMortal::pcMortal(float maxHp, float def, const char *corpseName) : Mortal(maxHp, def, corpseName) {}
npcMortal::npcMortal(float maxHp, float def, const char *corpseName) : Mortal(maxHp, def, corpseName) {}
void pcMortal::die(std::shared_ptr<Ent> owner) {
engine.gui->message(TCODColor::white, "You have been slain...\n");
Mortal::die(owner);
engine.gameState = Engine::LOSE;
}
void npcMortal::die(std::shared_ptr<Ent> owner) {
engine.gui->message(TCODColor::white, "The %s has perished.\n", owner->name);
Mortal::die(owner);
}