-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnemyObject.cpp
43 lines (37 loc) · 1013 Bytes
/
EnemyObject.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
//
// Created by nikang on 1/30/17.
//
#include "EnemyObject.h"
#include <QDebug>
int EnemyObject::height() const
{
return left.height();
}
int EnemyObject::width() const
{
return left.width();
}
EnemyObject::EnemyObject(QString leftAddress, QString rightAddress, int height, int score, double vX)
:left(QPixmap(leftAddress).scaledToHeight(height)),
right(QPixmap(rightAddress).scaledToHeight(height)),
MovingObject(score, Physics(vX), Physics())
{
if(vX > 0)
this->setPixmap(right);
else
this->setPixmap(left);
}
bool EnemyObject::isEnemy()
{
return true;
}
void EnemyObject::explode()
{
int expLength = qMin(this->height(), this->width());
QPoint center(this->x() + this->width() / 2, this->y() + this->height() / 2);
Explosion* explosion = new Explosion(expLength);
explosion->setPos(center.x() - expLength / 2, center.y() - expLength / 2);
this->scene()->addItem(explosion);
this->scene()->removeItem(this);
//delete this;
}