-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplosionEffect.cpp
More file actions
29 lines (27 loc) · 971 Bytes
/
ExplosionEffect.cpp
File metadata and controls
29 lines (27 loc) · 971 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
#include <cmath>
#include <string>
#include "ExplosionEffect.hpp"
#include "GameEngine.hpp"
#include "Group.hpp"
#include "IScene.hpp"
#include "PlayScene.hpp"
#include "Resources.hpp"
// TODO 4 (1/2): You can imitate the 2 files: 'ExplosionEffect.hpp', 'ExplosionEffect.cpp' to create shoot effect.
PlayScene* ExplosionEffect::getPlayScene() {
return dynamic_cast<PlayScene*>(Engine::GameEngine::GetInstance().GetActiveScene());
}
ExplosionEffect::ExplosionEffect(float x, float y) : Sprite("play/explosion-1.png", x, y), timeTicks(0) {
for (int i = 1; i <= 5; i++) {
bmps.push_back(Engine::Resources::GetInstance().GetBitmap("play/explosion-" + std::to_string(i) + ".png"));
}
}
void ExplosionEffect::Update(float deltaTime) {
timeTicks += deltaTime;
if (timeTicks >= timeSpan) {
getPlayScene()->EffectGroup->RemoveObject(objectIterator);
return;
}
int phase = floor(timeTicks / timeSpan * bmps.size());
bmp = bmps[phase];
Sprite::Update(deltaTime);
}