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.

35 lines
699 B

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