-
Notifications
You must be signed in to change notification settings - Fork 0
/
char.cpp
57 lines (41 loc) · 974 Bytes
/
char.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
#include "char.h"
Char::Char(){
xdir = 190; //Default location of character
ydir = 350;
image.load("char.png");//Load .png sprite for character
rect = image.rect();//Sets image to character and moves off screen
rect.moveTo(-50,-50);
}
Char::~Char() {
}
void Char::reset(){ //Resets location to default
xdir = 190;
ydir = 360;
rect.moveTo(190, 360);
}
void Char::move(){ //Moves character to selected point
rect.moveTo(QPoint(xdir,ydir));
}
void Char::move(int x, int y){
rect.moveTo(QPoint(x,y));
}
int Char::getXDir(){//Returns x and y coordinates
return xdir;
}
int Char::getYDir(){
return ydir;
}
void Char::setXDir(int x){ //Sets x and y coordinates with boundaries check
if(x>0 && x < 380)
xdir = x;
}
void Char::setYDir(int y){
if(y >35 && y <380)
ydir = y;
}
QRect Char::getRect(){ //Returns rect object assigned to character
return rect;
}
QImage& Char::getImage(){ //Returns .png assigned to character
return image;
}