-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
50 lines (41 loc) · 1.35 KB
/
Copy pathPlayer.cpp
File metadata and controls
50 lines (41 loc) · 1.35 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 "Player.h"
Player::Player() : VisualGameObject() { // sprawdz se potem czy mozesz po referencji in_guns wziac
std::wstring pattern = L" #---\\>` .//|#-->`::|||#-----|>` .\\\\|#-->` #---/>";
setDetailedName("Player");
setObjFacing(GameObject::controls::RIGHT);
setPattern(pattern);
setSize(13, 5);
setHealth(100);
setPos(0,10);
attachGun(new Gun(this, 50, 10, 0, 20));
attachGun(new Gun(this, 50, 12, 2, 20));
attachGun(new Gun(this, 50, 10, 4, 20));
}
void Player::attachGun(Gun* gun) {
guns.emplace_back(gun);
}
void Player::setHealth(short in_Health) {
m_health = in_Health;
}
short Player::getHealth() { return m_health; }
void Player::dealDamage(short in_Damage) {
m_health -= in_Damage;
if (m_health <= 0) {
for (Gun* gun : guns) {
delete gun;
}
guns.clear();
std::wstring noPattern = L" ";
setPattern(noPattern);
markForDeath(); // mark for deletion
}
}
void Player::shoot(short& in_controls, std::vector<VisualGameObject*>* bulletContainer) {
if ((in_controls & controls::SHOOT) != 0){
for (Gun* gun : guns) {
Bullet* bullet = gun->shoot(GameObject::controls::RIGHT);
if (bullet != nullptr) bulletContainer->emplace_back(bullet);
}
}
}
Player* Player::refer() { return this; }