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.
34 lines
699 B
34 lines
699 B
#include "enemy.h" |
|
#include <QTimer> |
|
#include <QGraphicsScene> |
|
#include <stdlib.h> |
|
#include "game.h" |
|
#include "health.h" |
|
|
|
extern Game* game; |
|
|
|
Enemy::Enemy(QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent) |
|
{ |
|
int random_number = rand() % 700; |
|
setPos(random_number,0); |
|
//setRect(0,0,100,100); |
|
setPixmap(QPixmap(":/images/enemy.png")); |
|
|
|
QTimer* timer = new QTimer(); |
|
connect(timer, SIGNAL(timeout()), this, SLOT(move())); |
|
timer->start(50); |
|
} |
|
|
|
|
|
void Enemy::move() |
|
{ |
|
this->setPos(x(), y()+5); |
|
if(pos().y() > 600) { |
|
game->health->decrease(); |
|
scene()->removeItem(this); |
|
delete this; |
|
//qDebug() << "bullet deleted"; |
|
} |
|
} |
|
|
|
|
|
|