This repository was archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplosion.cpp
72 lines (61 loc) · 1.54 KB
/
explosion.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "explosion.h"
#include "iostream"
Explosion::Explosion(QPoint point, Type type)
{
this->expType = type;
this->gameObjectType = GameObject::Type::Explosion;
if(expType == Type::EnemyDie){
pixmap = QPixmap(":/images/images/ExplosionSprites.png");
lives = 5;
makeFramesFromPixmap();
rect = QRect(point.x()-30,point.y()-30,frame->width()*3,frame->height()*3);
}else{
pixmap = QPixmap(":/images/images/ExplosionSprites2.png");
lives = 4;
makeFramesFromPixmap();
rect = QRect(point.x()-10,point.y()-10,frame->width()*3,frame->height()*3);
}
}
void Explosion::animate(Animation){
if(this->isAlive() && frame != frames.last()){
int index = frames.indexOf(frame);
frame = frames[index + 1];
}
if(!this->isAlive()){
frame = frames.last();
}
hurt();
}
void Explosion::makeFramesFromPixmap(){
frames.reserve(5);
for(int i=0; i<lives;i++){
frames.push_back(new QPixmap(pixmap.copy(30*i,0,30,24)));
}
QPixmap copy = frames.first()->copy();
frames.push_front(©);
frame = frames.first();
}
void Explosion::draw(std::shared_ptr<QPainter> painter)
{
painter->drawPixmap(rect,*frame);
}
void Explosion::move()
{
}
void Explosion::reuse(QPoint point)
{
rect.moveTopLeft(point - QPoint(30,30));
if(this->expType == Type::PlayerDie){
rect.moveTopLeft(point-QPoint(10,10));
}
if(this->expType == Type::EnemyDie){
lives = 5;
}else{
lives = 4;
}
frame = frames.first();
}
Explosion::Type Explosion::getType()
{
return this->expType;
}