-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetower.cpp
59 lines (46 loc) · 1.54 KB
/
bluetower.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
48
49
50
51
52
53
54
55
56
57
58
59
#include "bluetower.h"
#include <QTimer>
#include "bullet.h"
#include "game.h"
#include "triplearrow.h"
#include "enemy.h"
#include <typeinfo>
extern Game * game;
BlueTower::BlueTower(QGraphicsItem *parent)
{
QPixmap blueenemy(":/images/blue.png");
QPixmap newPixmap = blueenemy.scaled(QSize(50,50), Qt::KeepAspectRatio);
setPixmap(QPixmap(newPixmap));
QTimer * timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(acquire_target()));
timer->start(1500);
}
void BlueTower::fire()
{
QList<QGraphicsItem *> collidin_items = attack_area->collidingItems();
for (int i = 0, n = collidin_items.size(); i < n; ++i){
if (typeid(*(collidin_items[i])) == typeid(Enemy)){
triplearrow * bullet1 = new triplearrow();
triplearrow * bullet2 = new triplearrow();
triplearrow * bullet3 = new triplearrow();
bullet1->setPixmap(QPixmap(":/images/arrow.png"));
bullet2->setPixmap(QPixmap(":/images/arrow.png"));
bullet3->setPixmap(QPixmap(":/images/arrow.png"));
bullet1->setPos(x()+25,y()+25);
bullet2->setPos(x()+25,y()+25);
bullet3->setPos(x()+25,y()+25);
QLineF ln(QPointF(x()+25,y()+25),attack_dest);
int angle = -1 * ln.angle();
bullet1->setRotation(angle);
game->scene->addItem(bullet1);
bullet2->setRotation(angle+10);
game->scene->addItem(bullet2);
bullet3->setRotation(angle-10);
game->scene->addItem(bullet3);
}
}
}
void BlueTower::aquire_target()
{
Tower::acquire_target();
}