-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.cpp
48 lines (31 loc) · 820 Bytes
/
enemy.cpp
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
38
39
40
41
42
43
44
45
#include "enemy.h"
#include "gamebase.h"
#include <QTimer>
#include <QGraphicsScene>
#include <QList>
#include <stdlib.h>
#include <QDebug>
extern GameBase *game;
Enemy::Enemy(QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent)
{
int random_number = rand() % 700;
setPos(random_number,0);
// drew the rect
QPixmap pixmap(":/new/images/resource/images/enemy.png");
setPixmap(pixmap.scaled(50,50));
setTransformOriginPoint(25,25);
setRotation(180);
// connect
QTimer * timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(move()));
timer->start(50);
}
void Enemy::move()
{
setPos(x(),y()+5);
if (pos().y() > 600){
game->health->decrease();
scene()->removeItem(this);
delete this;
}
}