forked from Sicatriz/CppGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
46 lines (36 loc) · 1.12 KB
/
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
45
46
#include "bullet.h"
#include "enemy.h"
#include "enemy1.h"
#include "enemy2.h"
#include "enemy3.h"
#include "meteor1.h"
#include "meteor3.h"
#include "audio.h"
using namespace insemi;
Bullet::Bullet(QGraphicsItem *parent): MovableObjects(parent) //With Qobject you say this Bullet is a object, Qgraphics gives the bullet a size.
{
setPixmap(QPixmap(":/gfx/gfx/laser.png")); //give bullet graphics
QGraphicsPixmapItem::setOffset(2, 50);
}
Bullet::Bullet(QGraphicsItem* parent, int xas, int yas, Score* scoore): MovableObjects(parent)
{
setPixmap(QPixmap(":/gfx/gfx/laser.png")); //give bullet graphics
score = scoore;
// Offset ship to mousecursor
QGraphicsPixmapItem::setOffset(xas, yas);
Audio* bulletSound = new Audio();
bulletSound->playBullet(0.5);
}
void Bullet::move()
{
// get a list of all the items currently colliding with this bullet
// move bullet up by pixels
setPos(x(),y()-5);
//when bullet is out of screen, free memory and remove bullet
if(pos().y() < 0)
{
// Game().delItem(this);
//scene()->removeItem(this);
this->deleteLater();
}
}