-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.cpp
102 lines (88 loc) · 1.79 KB
/
character.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "character.h"
#include <ncurses.h>
Character::Character(WINDOW * win, int y, int x, char _symbol, bool _hunter) {
window = win;
yLoc = ySpawnLoc = y;
xLoc = xSpawnLoc = x;
symbol = _symbol;
hunter = _hunter;
direction = KEY_DOWN;
getmaxyx(window, yMax, xMax);
}
int Character::getX() {
return xLoc;
}
int Character::getNextX() {
if (direction == KEY_LEFT)
return xLoc - 1;
else if (direction == KEY_RIGHT)
return xLoc + 1;
else
return xLoc;
}
int Character::getY() {
return yLoc;
}
int Character::getNextY() {
if (direction == KEY_UP)
return yLoc - 1;
else if (direction == KEY_DOWN)
return yLoc + 1;
else
return yLoc;
}
int Character::getDirection() {
return direction;
}
bool Character::checkCollision(int y, int x) {
if (mvwinch(window, y, x) == wall || mvwinch(window, y, x) == symbol) {
return true;
}
return false;
}
bool Character::checkEnemyCollision(char enemy, int y, int x) {
if (mvwinch(window, yLoc, xLoc) == enemy ) {
return true;
} else if (mvwinch(window, y, x) == enemy ) {
return true;
}
return false;
}
void Character::display() {
mvwaddch(window, yLoc, xLoc, symbol);
}
void Character::revive() {
mvwaddch(window, yLoc, xLoc, ' ');
yLoc = ySpawnLoc;
xLoc = xSpawnLoc;
}
void Character::moveUp() {
if (!checkCollision(yLoc - 1, xLoc)) {
mvwaddch(window, yLoc, xLoc, ' ');
yLoc--;
}
}
void Character::moveDown() {
if (!checkCollision(yLoc + 1, xLoc)) {
mvwaddch(window, yLoc, xLoc, ' ');
yLoc++;
}
}
void Character::moveLeft() {
if (!checkCollision(yLoc, xLoc - 1)) {
mvwaddch(window, yLoc, xLoc, ' ');
if (xLoc - 1 == -1)
xLoc = 22;
else
xLoc--;
}
}
void Character::moveRight() {
if (!checkCollision(yLoc, xLoc + 1)) {
mvwaddch(window, yLoc, xLoc, ' ');
if (xLoc + 1 == 23)
xLoc = 0;
else
xLoc++;
}
}