diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 10:18:22 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 10:18:22 +0100 |
commit | 798948dbe6f012e194f053c4e862cf697f30b793 (patch) | |
tree | 32c71420d1188f98cfb41b6f0d9536c5fa4bf5a7 /backend/Player.cpp | |
parent | d7012045bb61f117fb7b9c51ddd03e4c54f25fe6 (diff) |
more WIP (move some Player things to backend)
Diffstat (limited to 'backend/Player.cpp')
-rw-r--r-- | backend/Player.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/backend/Player.cpp b/backend/Player.cpp new file mode 100644 index 0000000..a113a21 --- /dev/null +++ b/backend/Player.cpp @@ -0,0 +1,59 @@ +#include <assert.h> + +#include "Player.h" +#include "print.h" +#include "Dungeon.h" +#include "util.h" + +Player::Player(Dungeon & dungeon) : dungeon(dungeon) { } + +float Player::get_attack() const { + if (this->cheating) return 1.f; + return this->attack_chance; +} + +unsigned Player::get_health() const { + return this->health_points; +} + +void Player::take_damage(unsigned int dmg) { + if (this->cheating) return; + + dmg = min(dmg, this->health_points); + this->health_points -= dmg; + + lprtf("Je hebt nog %d levenspunten over.\n", this->health_points); +} + +Location & Player::get_location() const { + assert(this->location != nullptr); + return *this->location; +} +void Player::set_location(Location & location) { + this->location = &location; +} + +void Player::equip(WeaponObject * weapon) { + if (weapon == nullptr) return; + + lprtf("Je "); + if (this->weapon != nullptr) { + lprtf("laat %s vallen en ", this->weapon->get_name().c_str()); + this->inventory.push_back(this->weapon); + } + this->weapon = weapon; + lprtf("pakt %s vast.\n", this->weapon->get_name().c_str()); +} + +void Player::equip(ArmorObject * armor) { + if (armor == nullptr) return; + + lprtf("Je "); + if (this->armor != nullptr) { + lprtf("trekt %s uit en ", this->armor->get_name().c_str()); + this->inventory.push_back(this->armor); + } + this->armor = armor; + lprtf("doet %s aan.\n", this->armor->get_name().c_str()); +} + |