-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemylongrange.cpp
65 lines (59 loc) · 1.46 KB
/
enemylongrange.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
#include "enemylongrange.h"
#include "gamewindow.h"
/** Default constructor. Creates a Long Range Enemy with the specified parameters.
* @param pixmap The Pixmap to display this object with
* @param parent The GameWindow which created this object
* @param scene The scene in which this object exists
*/
EnemyLongRange::EnemyLongRange(QPixmap & pixmap, GameWindow * parent, QGraphicsScene *scene) : Thing(pixmap, 0, 0)
{
shoots = true;
offscreen = false;
srand(time(NULL));
scene_ = scene;
parent_ = parent;
cooldown = (200 + rand() % 190);
vy_ = 1;
x_ = (rand() % 420 + 2);
vx_ = (-2 + (rand() % 5));
y_ = -50;
setPos(x_, y_);
setZValue(5);
yBarrier = ((rand() % 100) + 200);
health_ = 2;
score = 50;
}
/** Destructor */
EnemyLongRange::~EnemyLongRange()
{
}
/** Moves the EnemyLongRange according to it's current velocities and the randomly generated yBarrier.
*/
void EnemyLongRange::move()
{
if (y_ > parent_->ySize_ )
offscreen = true;
if (y_ > yBarrier && vy_ > 0)
{
vy_ = -vy_;
if (vx_ == 0)
vx_ = -1;
if (vx_ == -2)
vx_ ++;
if (vx_ == 2)
vx_ --;
}
if ( vy_ < 0 && y_ < -40)
{
vy_ = -vy_;
if (vx_ == 1)
vx_ ++;
if (vx_ == -1)
vx_ --;
}
if (x_ < 0 || x_ > (parent_->xSize_ - pixmap().width()))
vx_ = -vx_;
y_ += vy_;
x_ += vx_;
setPos(x_, y_);
}