-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
50 lines (46 loc) · 1.47 KB
/
player.cpp
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
50
#include "player.h"
Player::~Player() {
}
// update the player
void Player::Brain(map_type map, std::vector<Entity*>& residents) {
if (!dead_) {
int ch = GetLastCh();
// manage input for movement
if (ch == '8' || ch == KEY_UP) {
MoveAttack(-1, 0, map, residents);
} else if (ch == '9') {
MoveAttack(-1, 1, map, residents);
} else if (ch == '6' || ch == KEY_RIGHT) {
MoveAttack(0, 1, map, residents);
} else if (ch == '3') {
MoveAttack(1, 1, map, residents);
} else if (ch == '2' || ch == KEY_DOWN) {
MoveAttack(1, 0, map, residents);
} else if (ch == '1') {
MoveAttack(1, -1, map, residents);
} else if (ch == '4' || ch == KEY_LEFT) {
MoveAttack(0, -1, map, residents);
} else if (ch == '7') {
MoveAttack(-1,-1, map, residents);
} else if (ch == '5') {
MoveAttack(0, 0, map, residents);
}
// actions
// get item on the ground
if (ch == 'g') {
for (Entity* entity : residents) {
if (entity->GetY() == GetY() && entity->GetX() == GetX()) {
TakeItems(entity);
}
}
}
}
}
void Player::CheckDead(std::vector<Entity*>& residents) {
if (hp_ <= 0) {
// if dead, stop doing stuff
main_log->AddMessage("You are Dead!");
color_pair_ = 5;
dead_ = true;
}
}