-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtower.cpp
46 lines (38 loc) · 926 Bytes
/
tower.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
#include "tower.h"
Tower::Tower(double x, double y, QImage *i) : GameObject(x, y, i)
{
InitializeInstanceFields();
double width = i->width(), height = i->height();
double cx = (x + width / 2) - xRange / 2, cy = (y + height / 2) - yRange / 2;
range = new QRect(cx, cy, xRange, yRange);
targetLocation = new QPoint(myX, myY);
}
bool Tower::enemyDetected(GameObject *target)
{
QRect* rectTarget = target->getRect();
if (range->intersects(*rectTarget))
return true;
return false;
}
void Tower::drag()
{
myX = targetLocation->x();
myY = targetLocation->y();
}
QRect *Tower::getRange()
{
return range;
}
QPoint *Tower::getTargetLocation()
{
return targetLocation;
}
void Tower::setTargetLocation(QPoint *point)
{
targetLocation = point;
}
void Tower::InitializeInstanceFields()
{
xRange = 200;
yRange = 200;
}