-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
41 lines (35 loc) · 924 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
#include "bullet.h"
#include "gamecontroller.h"
#include <QPainter>
Bullet::Bullet(GameController &controller):
controller(controller)
{
setData(GD_type, GO_Bullet);
pixMap.load("://images/Bullet.png");
speed = 8;
}
QRectF Bullet::boundingRect() const
{
int w = pixMap.width(), h = pixMap.height();
return QRectF(-w/2, -h/2, w, h);
}
void Bullet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option); Q_UNUSED(widget);
if(!pixMap.isNull()) {
painter->save();
int w = pixMap.width(), h = pixMap.height();
painter->drawPixmap(QPoint(-w/2, -h/2), pixMap);
painter->restore();
}
}
void Bullet::advance(int phace)
{
if(!phace) return;
moveBy(0, -speed);
if(!isInView(pos())) controller.removeItem(this);
}
void Bullet::setSpeed(int x)
{
speed = x;
}