-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondTower.cpp
More file actions
55 lines (45 loc) · 1.29 KB
/
SecondTower.cpp
File metadata and controls
55 lines (45 loc) · 1.29 KB
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
#include "SecondTower.h"
#include <QTimer>
#include "bullet.h"
#include "game.h"
#include <QLineF>
extern Game *game;
SecondTower::SecondTower(QGraphicsItem *parent)
{
//set tower
setPixmap(QPixmap(":/images/secondtower.png"));
//connect timer to attack
QTimer *timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(acquire_target()));
timer->start(1000);
//attack color
QPen pen;
pen.setColor(Qt::darkBlue);
attack_area->setPen(pen);
}
void SecondTower::fire()
{
//create bullet
Bullet *bullet = new Bullet();
Bullet *bullet1 = new Bullet();
Bullet *bullet2 = new Bullet();
//set grapchics
bullet->setPixmap(QPixmap(":/images/secondtowerbullet.png"));
bullet1->setPixmap(QPixmap(":/images/secondtowerbullet.png"));
bullet2->setPixmap(QPixmap(":/images/secondtowerbullet.png"));
bullet->setPos(x()+50,y()+50);
bullet1->setPos(x()+50,y()+50);
bullet2->setPos(x()+50,y()+50);
QLineF ln(QPoint(x()+50,y()+50),attack_dest);
int angle = -1*ln.angle();
bullet->setRotation(angle);
bullet1->setRotation(angle+10);
bullet2->setRotation(angle-10);
scene()->addItem(bullet);
scene()->addItem(bullet1);
scene()->addItem(bullet2);
}
void SecondTower::acquire_target()
{
Tower::acquire_target();
}