-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathplant.cpp
44 lines (37 loc) · 833 Bytes
/
plant.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
#include "plant.h"
#include "zombie.h"
Plant::Plant()
{
movie = nullptr;
atk = counter = state = time = 0;
}
Plant::~Plant()
{
delete movie;
}
QRectF Plant::boundingRect() const
{
return QRectF(-35, -35, 70, 70);
}
void Plant::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->drawImage(boundingRect(), movie->currentImage());
}
bool Plant::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
Q_UNUSED(mode)
return other->type() == Zombie::Type && qFuzzyCompare(other->y(), y()) && qAbs(other->x() - x()) < 30;
}
int Plant::type() const
{
return Type;
}
void Plant::setMovie(QString path)
{
if (movie)
delete movie;
movie = new QMovie(path);
movie->start();
}