-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
44 lines (36 loc) · 842 Bytes
/
bullet.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 "bullet.h"
Bullet::Bullet(QGraphicsItem* parent)
: QGraphicsRectItem(parent)
{
setRect(0,0,10,20);
//make the bullet move
QTimer* timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(move()));
timer->start(10);
}
Bullet::~Bullet()
{
this->deleteLater();
}
QRectF Bullet::boundingRect() const
{
return rect();
}
void Bullet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget);
//draw the bullet
QPen pen(Qt::NoPen);
painter->setPen(pen);
painter->drawRect(option->rect);
painter->drawPixmap(option->rect,QPixmap(":/images/bullet.jpg"));
}
void Bullet::move()
{
setPos(x(),y() - oneMove);
//check if the bullet get over the top of scene
if(y() <= 50)
{
this->deleteLater();
}
}