-
Notifications
You must be signed in to change notification settings - Fork 0
/
obstacle.cpp
112 lines (90 loc) · 1.9 KB
/
obstacle.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
#include "obstacle.h"
Obstacle::Obstacle(QLabel *nObstacle, double nx, double ny, double w, double h, int vx, int vy, Dragon *d )
{
x = nx;
y = ny;
width = w;
height = h;
velocityX = vx;
velocityY = vy;
obstacle = nObstacle;
dragon = d;
obstacle->setAttribute(Qt::WA_TranslucentBackground);
}
Obstacle::~Obstacle()
{
delete obstacle;
//obstacle->setPixmap(NULL);
}
int Obstacle::getVelocityX() {
return velocityX;
}
int Obstacle::getVelocityY() {
return velocityY;
}
void Obstacle::setVelocityX( int vx ) {
velocityX = vx;
}
void Obstacle::setVelocityY( int vy ) {
velocityY = vy;
}
int Obstacle::move( int windowMaxX, int windowMaxY ) {
// 0: obstacle+no hit, 1: obstacle+hit, 2: red_potion, 3: magic_potion
x += velocityX;
y += velocityY;
if ( x < 0 ) {
//delete obstacle;
return 0;
}
if ( y < 0 ) {
//delete obstacle;
return 0;
}
if ( (x+width) > windowMaxX *2.49 ) {
//delete obstacle;
return 0;
}
if ( (y+height) > windowMaxY *2.49 ) {
//delete obstacle;
return 0;
}
obstacle->move(x,y);
if(hitCheck() == 1) // Obstacle
return 1;
else if(hitCheck() == 2) // red_potion
return 2;
else if(hitCheck() == 3) // magic_potion
return 3;
return 4;
}
int Obstacle::hitCheck()
{
double dx = dragon->getX();
double dy = dragon->getY();
int dsize = dragon->getSize();
int buffer = 34;
if( x + width > dx + buffer && x + buffer < dx + dsize){
if( y + height > dy + buffer && y + buffer < dy + dsize){
// 77:R, 78:W
if(width == 77)
return 2;
else if(width == 78)
return 3;
else
return 1;
}
}
return 0;
}
int Obstacle::getX() {
return x;
}
int Obstacle::getY() {
return y;
}
void Obstacle::setX(int nx) {
x = nx;
}
void Obstacle::setY(int ny) {
y = ny;
}