-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcannon.cpp
More file actions
30 lines (25 loc) · 735 Bytes
/
cannon.cpp
File metadata and controls
30 lines (25 loc) · 735 Bytes
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
#include "cannon.h"
#include <QGraphicsScene>
CCannon::CCannon(QGraphicsItem *pParent) : QGraphicsPixmapItem(pParent)
{
QPixmap pixmap;
pixmap.load(":/Resources/RedCannon.png");
setPixmap(pixmap.scaled(QSize(100, 100), Qt::KeepAspectRatio));
}
void CCannon::shoot()
{
if (bullet == nullptr)
{
bullet = new CBullet(-30);
connect(bullet, &CBullet::sigIncreaseScore, this, &CCannon::sigIncreaseScore);
connect(bullet, &CBullet::sigDeleted, this, &CCannon::onDeleted);
// the bullet position is changed
bullet->setPos(x() + 27, y() - 10);
// we add the bullet to the scene
scene()->addItem(bullet);
}
}
void CCannon::onDeleted()
{
bullet = nullptr;
}