You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

20 lines
538 B

#include "bullet.h"
#include <QTimer>
#include <qmath.h>
Bullet::Bullet(QGraphicsItem *parent) {
// set graphics
setPixmap(QPixmap(":/images/missile.png"));
QTimer *move_timer = new QTimer(this);
connect(move_timer, SIGNAL(timeout()), this, SLOT(move()));
move_timer->start(50);
}
void Bullet::move() {
int STEP_SIZE = 30;
int theta = rotation(); // degrees
double dy = STEP_SIZE * qSin(qDegreesToRadians(theta));
double dx = STEP_SIZE * qCos(qDegreesToRadians(theta));
setPos(x()+dx, y()+dy);
}