-
Notifications
You must be signed in to change notification settings - Fork 0
/
Character.cpp
205 lines (165 loc) · 2.93 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "Character.h"
bool Character::isInvincible()
{
return invincible;
}
//Constructors
Character::Character() {
//Position
curX = 0;
curY = 0;
angle = 0;
//Starting stats
maxHp = 100;
curHp = 100;
damage = 10;
ms = 10;
atkSpd = 10;
//Level Stats
//Flags
alive = false;
moving = false;
hidden = false;
counter = 0;
}
float Character::getCurHp()
{
return curHp;
}
float Character::getMaxHp()
{
return maxHp;
}
float Character::getMs()
{
return 0;
}
float Character::getAtkSpd()
{
return atkSpd;
}
float Character::getDamage()
{
return damage;
}
float Character::getCurX()
{
return curX;
}
float Character::getCurY()
{
return curY;
}
float Character::getAngle()
{
return angle;
}
sf::Vector2f Character::getCurVelocity()
{
return curVelocity;
}
int Character::getCounter()
{
return counter;
}
bool Character::isHidden()
{
return hidden;
}
void Character::setHidden(bool x)
{
hidden = x;
}
void Character::setMs(float x)
{
ms = x;
}
void Character::setDamage(float x)
{
damage = x;
}
void Character::incrementCounter()
{
counter++;
}
void Character::resetCounter()
{
counter = 0;
}
//HP Functions
void Character::takeDamage(int dmgTaken) {
curHp -= dmgTaken;
if (curHp <= 0) {
death();
}
}
void Character::heal(int healthGain) {
curHp += healthGain;
if (curHp > maxHp) {
curHp = maxHp;
}
}
void Character::updatePosition(float x, float y)
{
curX = x;
curY = y;
}
void Character::updateAngle(float x)
{
angle = x;
}
void Character::pointMouseCursor(sf::RenderWindow& win)
{
auto curPos = getPosition();
auto position = sf::Mouse::getPosition(win);
const float PI = 3.14159;
float dx = curPos.x - position.x;
float dy = curPos.y - position.y;
setRotation(atan2(dy, dx) * 180 / PI);
}
void Character::moveTowardMouse(sf::RenderWindow& win)
{
if (moving) {
move(curVelocity * ms);
}
else {
auto curPos = getPosition();
auto position = sf::Mouse::getPosition(win);
float dx = curPos.x - position.x;
float dy = curPos.y - position.y;
float mag = -1*sqrt(dx * dx + dy*dy);
curVelocity = sf::Vector2f(dx/mag,dy/mag);
moving = true;
}
}
void Character::moveToPos(sf::Vector2f pos)
{
if (moving) {
move(curVelocity * ms);
}
else {
auto curPos = getPosition();
float dx = curPos.x - pos.x;
float dy = curPos.y - pos.y;
float mag = -1 * sqrt(dx * dx + dy * dy);
curVelocity = sf::Vector2f(dx / mag, dy / mag);
moving = true;
}
}
void Character::moveToPos(float x, float y)
{
if (moving) {
move(curVelocity * ms);
}
else {
auto curPos = getPosition();
float dx = curPos.x - x;
float dy = curPos.y - y;
float mag = -1 * sqrt(dx * dx + dy * dy);
curVelocity = sf::Vector2f(dx / mag, dy / mag);
moving = true;
}
}
//End Game Functions
void Character::death() {
}