-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bullet.cpp
47 lines (44 loc) · 1.26 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
47
//
// Created by nikang on 1/30/17.
//
#include <typeinfo>
#include <QGraphicsScene>
#include <QDebug>
#include "Bullet.h"
#include "EnemyObject.h"
#include "Jet.h"
#include <QDebug>
#include<typeinfo>
#include"Wall.h"
Bullet::Bullet(Game* game, Player* player, double vY) : Object(Physics(), Physics(vY))
{
this->game = game;
this->player = player;
setPixmap(QPixmap(":/images/missile.png").scaledToHeight(10));
}
void Bullet::advance(int phase)
{
QList<QGraphicsItem *> colliding_items = collidingItems();
for(int i = 0 , n = colliding_items.size() ; i < n ; i++ )
{
if(((Object*)colliding_items[i])->isEnemy() || typeid(*(colliding_items[i])) == typeid(DepotFuel))
{
game->addScore(((MovingObject*)colliding_items[i])->getScore());
((Object*)(colliding_items[i]))->explode();
this->explode();
return;
}
else if(typeid(*(colliding_items[i])) == typeid(Wall))
this->explode();
}
// qDebug() << x() <<" " << y() << " " << getDeltaY();
setPos(player->x() + player->getWidth() / 2 , y() + yPhys.movement());
if(y() < 0)
this->explode();
}
void Bullet::explode()
{
player->setHasBullet(false);
this->scene()->removeItem(this);
delete this;
}