-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsunflower.cpp
More file actions
61 lines (49 loc) · 1.35 KB
/
sunflower.cpp
File metadata and controls
61 lines (49 loc) · 1.35 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
#include "sunflower.h"
int Sunflower::seedingTime = 7500;
Sunflower::Sunflower(QRect *plant_row)
{
//sunflower properties
life = 4;
cost = 50;
plantDamage = 0;
fireRate = 24000;
//Sets the position of sunflower based on the rectangle it is planted on
this->setPos(plant_row->x(),plant_row->y());
//loads the sunflower image
sunflowerImage = new QPixmap(":/Images/sunflower");
makeSunCounter = new QTime; //loads QTime counter
makeSunCounter->start(); //starts the counter
}
Sunflower::~Sunflower()
{
delete sunflowerImage;
delete makeSunCounter;
}
QRectF Sunflower::boundingRect() const
{
return QRectF(0,0,sunflowerImage->width(),sunflowerImage->height());
}
void Sunflower::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//Draws sunflowerImage
painter->drawPixmap(boundingRect(),*sunflowerImage,boundingRect());
}
void Sunflower::advance(int phase)
{
if(!phase) return;
//destroys sunflower instance if health is 0 or less
if(life <= 0)
{
delete this;
return;
}
//Checks to see if counter has reached the set firerate
if(makeSunCounter->elapsed() >= fireRate)
{
//makes a new sun(type 2)
sun = new Sun(this);
scene()->addItem(sun);
//Restarts the counter
makeSunCounter->restart();
}
}