-
Notifications
You must be signed in to change notification settings - Fork 1
/
monsterSkeleton.cpp
143 lines (117 loc) · 1.71 KB
/
monsterSkeleton.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
#include "monsterSkeleton.h"
#include "monster.h"
#include <iostream>
Skeleton::Skeleton(): Monster()
{
xdir = 1;
ydir = -1;
image.load("GhostMonster.png"); //friend's drawing
rect = image.rect();
resetState();
}
Skeleton::~Skeleton() {
//std::cout << ("Skeleton deleted\n");
}
void Skeleton::setAppeared(bool a)
{
appear = a;
}
bool Skeleton::hasAppeared()
{
return appear;
}
void Skeleton::autoMove()
{
rect.translate(xdir, ydir);
if (rect.left() <= 4) {
xdir = 2;
}
if (rect.right() >= 494) {
xdir = -2;
}
if (rect.top() <= 2) {
ydir = 2;
}
if (rect.bottom() >= 600)
{ ydir = -2;
}
}
bool Skeleton::isDead()
{
return dead;
}
void Skeleton::setDead(bool d)
{
dead = d;
}
void Skeleton::resetState()
{
rect.moveTo(rand()% 400, rand() % 400);
moving = true;
appear = false;
dead = false;
}
void Skeleton::compare(int X, int Y)
{
if (rect.left() > X)
xdir = -1;
else if (rect.left() == X)
xdir = 0;
else
xdir = 1;
if (rect.top() < Y)
ydir = 1;
else if (rect.top() == Y)
ydir = 0;
else
ydir = -1;
rect.translate(xdir,ydir);
}
void Skeleton::moveBottom(int bottom)
{
rect.moveBottom(bottom);
}
void Skeleton::moveTop(int top)
{
rect.moveTop(top);
}
void Skeleton::moveLeft(int left)
{
rect.moveLeft(left);
}
void Skeleton::moveRight(int right)
{
rect.moveRight(right);
}
void Skeleton::setXDir(int x)
{
xdir = x;
}
void Skeleton::setYDir(int y)
{
ydir = y;
}
int Skeleton::getXDir()
{
return xdir;
}
int Skeleton::getYDir()
{
return ydir;
}
void Skeleton::setMoving(bool m)
{
moving = m;
}
bool Skeleton::isMoving()
{
return moving;
}
QRect Skeleton::getRect()
{
return rect;
}
QImage & Skeleton::getImage()
{
return image;
}