#include "tower.h" #include #include #include #include "bullet.h" #include #include "game.h" extern Game *game; Tower::Tower(QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent) { setPixmap(QPixmap(":/images/tower.png")); // create points vectors QVector points; points << QPoint(1,0) << QPoint(2,0) << QPoint(3,1) << QPoint(3,2) << QPoint(2,3) << QPoint(1,3) << QPoint(0,2) << QPoint(0,1); // scale points int SCALE_FACTOR = 70; for (size_t i = 0, n = points.size(); i 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); }