-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.cpp
More file actions
37 lines (30 loc) · 863 Bytes
/
enemy.cpp
File metadata and controls
37 lines (30 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "enemy.h"
#include <QTimer>
#include <QDebug>
#include <QGraphicsScene>
#include <stdlib.h> // rand()
#include "game.h"
extern Game* game;
Enemy::Enemy(QGraphicsItem* parent): QObject(), QGraphicsPixmapItem(parent){
// set random position
int random_number = rand()%700;
setPos(random_number, 0);
// drew the rect
//setRect(0,0,100,100);
setPixmap(QPixmap(":/images/enemy1.gif"));
// connect
QTimer * timer = new QTimer();
connect(timer,SIGNAL(timeout()),this,SLOT(move()));
timer->start(50);
}
void Enemy::move(){
// move enemy down
setPos(x(),y()+5);
// checking if the bullet is off the screen
if (pos().y() > 600){
game->health->decrease();
scene()->removeItem(this);
delete this;
qDebug() << "enemy deleted";
}
}