Georg Spar
2 years ago
7 changed files with 51 additions and 1 deletions
@ -0,0 +1,20 @@
|
||||
#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); |
||||
} |
@ -0,0 +1,14 @@
|
||||
#ifndef BULLET_H |
||||
#define BULLET_H |
||||
#include <QGraphicsPixmapItem> |
||||
#include <QObject> |
||||
|
||||
class Bullet: public QObject, public QGraphicsPixmapItem { |
||||
Q_OBJECT |
||||
public: |
||||
Bullet(QGraphicsItem *parent=0); |
||||
public slots: |
||||
void move(); |
||||
}; |
||||
|
||||
#endif // BULLET_H
|
After Width: | Height: | Size: 7.1 KiB |
Loading…
Reference in new issue