|
|
|
@ -2,8 +2,13 @@
|
|
|
|
|
#include <QPixmap> |
|
|
|
|
#include <QVector> |
|
|
|
|
#include <QPointF> |
|
|
|
|
#include "bullet.h" |
|
|
|
|
#include <QTimer> |
|
|
|
|
#include "game.h" |
|
|
|
|
|
|
|
|
|
Tower::Tower(QGraphicsItem *parent) { |
|
|
|
|
extern Game *game; |
|
|
|
|
|
|
|
|
|
Tower::Tower(QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent) { |
|
|
|
|
setPixmap(QPixmap(":/images/tower.png")); |
|
|
|
|
|
|
|
|
|
// create points vectors
|
|
|
|
@ -30,4 +35,21 @@ Tower::Tower(QGraphicsItem *parent) {
|
|
|
|
|
QLineF ln(poly_center, tower_center); |
|
|
|
|
attack_area->setPos(x()+ln.dx(), y()+ln.dy()); |
|
|
|
|
|
|
|
|
|
// connect timer to attack target
|
|
|
|
|
QTimer *timer = new QTimer(); |
|
|
|
|
connect(timer, SIGNAL(timeout()), this,SLOT(attack_target())); |
|
|
|
|
timer->start(1000); |
|
|
|
|
|
|
|
|
|
attack_dest = QPointF(800,0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Tower::attack_target() { |
|
|
|
|
Bullet *bullet = new Bullet(); |
|
|
|
|
bullet->setPos(x()+34, y()+64); |
|
|
|
|
|
|
|
|
|
QLineF ln(QPointF(x()+34, y()+64), attack_dest); |
|
|
|
|
int angle = -1 * ln.angle(); |
|
|
|
|
|
|
|
|
|
bullet->setRotation(angle); |
|
|
|
|
game->scene->addItem(bullet); |
|
|
|
|
} |
|
|
|
|