-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreasurehunter.cpp
More file actions
109 lines (100 loc) · 1.68 KB
/
treasurehunter.cpp
File metadata and controls
109 lines (100 loc) · 1.68 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
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
#include "treasurehunter.h"
TreasureHunter::TreasureHunter(QPixmap* s, QPixmap* l1, QPixmap* l2, QPixmap* r1, QPixmap* r2, int nx, int ny) : QGraphicsPixmapItem(*s) {
x = nx;
y = ny;
setPos(x,y);
width = 20;
height = 35;
vX = 35;
vY = 50;
still = s;
left1 = l1;
left2 = l2;
right1 = r1;
right2 = r2;
animation = 0;
}
void TreasureHunter::animate(int timer){
if(timer % 15 == 0){
if(animation == 0){
setPixmap(*left1);
}
else if (animation == 1){
setPixmap(*left2);
}
else if (animation == 2){
setPixmap(*left1);
}
else if (animation == 3){
setPixmap(*still);
}
else if (animation == 4){
setPixmap(*right1);
}
else if (animation == 5){
setPixmap(*right2);
}
else if (animation == 6){
setPixmap(*right1);
}
else if (animation == 7){
setPixmap(*still);
animation = -1;
}
animation++;
}
}
void TreasureHunter::move(int direction){
if(direction == 0){
y += vY;
}
else if(direction == 1){
x += vX;
}
else if(direction == 2){
y-=vY;
}
else if(direction == 3){
x = x-vX;
}
if(x+width > 700){
x = 700-width;
}
else if(x<0){
x = 0;
}
if(y > 531){
y = 530;
}
else if(y < 115){
y+=vY;
}
setPos(x,y);
}
int TreasureHunter::getX(){
return x;
}
int TreasureHunter::getY(){
return y;
}
int TreasureHunter::getWidth(){
return width;
}
int TreasureHunter::getHeight(){
return height;
}
void TreasureHunter::logMove(int v){
x+= v;
if(x<0){
x = 0;
}
else if(x+width > 700){
x = 700-width;
}
setPos(x,y);
}
void TreasureHunter::setLoc(int nx, int ny){
setPos(nx,ny);
x = nx;
y = ny;
}