-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaiTower.cpp
41 lines (32 loc) · 936 Bytes
/
SaiTower.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
/** @file SaiTower.cpp
@brief This file contains member function definitions for the SaiTower class.
SaiTower fires projectiles at enemies.
*/
#include "SaiTower.h"
#include <QTimer>
#include "Projectile.h"
#include "Game.h"
extern Game* game;
SaiTower::SaiTower(QGraphicsItem *parent)
{
// connect a timer to attack_target
QTimer* timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(aquire_target()));
timer->start(1574); //fire rate
}
void SaiTower::fire()
{
// create the Projectiles
Projectile * projectile = new Projectile();
// set the graphics
projectile->setPixmap(QPixmap(":/images/tiger.png"));
projectile->setPos(x()+40,y()+50);
QLineF ln(QPointF(x()+40,y()+50),attack_dest);
int angle = -1 * ln.angle();
projectile->setRotation(angle+(rand()%41-20));
game->scene->addItem(projectile);
}
void SaiTower::aquire_target()
{
Tower::aquire_target();
}