-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplant.cpp
133 lines (113 loc) · 2.39 KB
/
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
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
#include <QDebug>
#include "plant.h"
Plant::Plant(QString name, QObject* parent) :
plantName(name), typeName("plant"), healthPoint(200)
{
hasZombie = false;
xShift = yShift = 0;
// setMinimumSize(40,40);
// resetHealthPoint();
movie = new QMovie(":/images/"+name+".gif");
movie->start();
/*
QLabel *plant = new QLabel(this);
QMovie *movie = new QMovie(":/images/"+name+".gif");
plant->setMovie(movie);
movie->start();
plant->show();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(plant);
*/
// the following are for debug
/*
layout->addWidget(bite);
layout->addWidget(hp);
*/
/*
this->setLayout(layout);
*/
}
Plant::~Plant()
{
delete(movie);
}
int Plant::type() const
{
return Type;
}
QRectF Plant::boundingRect() const
{
qreal adjust = 0.5;
return QRectF(-18 - adjust, -22 - adjust,
140 + adjust, 180 + adjust);
}
QPainterPath Plant::shape() const
{
QPainterPath path;
path.addRect(0, 0, 90, 100);
return path;
}
void Plant::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//painter->drawPixmap(0,0,QPixmap(":/images/"+plantName+".gif"));
// painter->drawPixmap(0,0,movie->currentPixmap());
painter->drawImage(xShift,yShift,movie->currentImage());
// painter->drawRect(0,0,90,100);
}
void Plant::advance(int step)
{
if (!step)
return;
update();
// setPos(mapToParent(-1, 0));
}
void Plant::pause()
{
movie->setPaused(true);
}
void Plant::restore()
{
movie->start();
}
void Plant::setPlanted()
{
planted = true;
}
void Plant::bitten(Plant* pp, int num)
{
if (pp != this)
return;
healthPoint -= num;
//if (healthPoint > 100)
// qDebug()<<"find wallNut";
// qDebug()<<"hp now "<<healthPoint;
emit hpChanged(healthPoint);
if (healthPoint <= 0){
emit destroyMe(this);
}
}
/*
void Plant::resetHealthPoint()
{
healthPoint = originHealthPoint;
emit hpChanged(healthPoint);
}
*/
void Plant::setLocation(int row, int col)
{
myRow = row;
myCol = col;
}
void Plant::seeZombie(int row, int col)
{
// qDebug()<<"comes to seeZombie in plant";
}
void Plant::sendPea()
{
}
void Plant::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
//QGraphicsScene::mousePressEvent(event);
event->ignore();
}