-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
53 lines (45 loc) · 1.13 KB
/
Character.cpp
File metadata and controls
53 lines (45 loc) · 1.13 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
50
51
52
53
#include "Character.h"
Character::Character(double x, double y) : DrawObject(x,y,2), life(100){
X = x;
Y = y;
};
Character::~Character(){
};
//***********************************************
// OTHER FUNCTIONS
//***********************************************
void Character::draw(){};
void Character::goUp(){
if(legalMovement(X, Y - vel)){
Y -= vel;
}
};
void Character::goDown(){
if(legalMovement(X, Y + vel)){
Y += vel;
}
};
void Character::goRight(){
if (legalMovement(X + vel, Y)){
X += vel;
}
};
void Character::goLeft(){
if(legalMovement(X - vel, Y)){
X -= vel;
}
};
bool Character::legalMovement(double x, double y) const {
if (x > leftLimit && x < rightLimit && y > upperLimit && y < bottomLimit){
return true;
}else{
return false;
}
};
//***********************************************
// GETTERS/SETTERS
//***********************************************
void Character::setLife(int new_life){if(new_life < 100) life = new_life;};
int Character::getLife() const {return life;};
double Character::getX() const {return X;};
double Character::getY() const {return Y;};