-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoottower.cpp
46 lines (34 loc) · 1.03 KB
/
shoottower.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 "shoottower.h"
#include <QTimer>
#include "bullet.h"
#include "game.h"
#include "enemy.h"
#include <typeinfo>
extern Game * game;
ShootTower::ShootTower(QGraphicsItem *parent)
{
QPixmap blueenemy(":/images/shoot.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(2000);
}
void ShootTower::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)){
Bullet * bullet = new Bullet();
bullet->setPos(x()+25,y()+25);
QLineF ln(QPointF(x()+25,y()+25),attack_dest);
int angle = -1 * ln.angle();
bullet->setRotation(angle);
game->scene->addItem(bullet);
}
}
}
void ShootTower::aquire_target()
{
Tower::acquire_target();
}