Debian Codegraph @

Sources/Jazz2/Actors/Environment/AirboardGenerator.cpp

raw
1 #include "AirboardGenerator.h"
2 #include "../../ILevelHandler.h"
3 #include "../Player.h"
4 #include "../Explosion.h"
5
6 #include "../../../nCine/Base/FrameTimer.h"
7
8 namespace Jazz2::Actors::Environment
9 {
10 AirboardGenerator::AirboardGenerator()
11 : _timeLeft(0.0f), _active(false)
12 {
13 }
14
15 Task<bool> AirboardGenerator::OnActivatedAsync(const ActorActivationDetails& details)
16 {
17 _delay = details.Params[0];
18 _active = true;
19
20 async_await RequestMetadataAsync("Object/Airboard"_s);
21
22 SetAnimation(AnimState::Default);
23
24 async_return true;
25 }
26
27 void AirboardGenerator::OnUpdate(float timeMult)
28 {
29 if (!_active) {
30 if (_timeLeft <= 0.0f) {
31 _active = true;
32 _renderer.setDrawEnabled(true);
33 }
34
35 _timeLeft -= timeMult;
36 }
37 }
38
39 bool AirboardGenerator::OnHandleCollision(std::shared_ptr<ActorBase> other)
40 {
41 if (auto* player = runtime_cast<Player>(other.get())) {
42 if (_active && player->SetModifier(Player::Modifier::Airboard)) {
43 _active = false;
44 _renderer.setDrawEnabled(false);
45
46 _timeLeft = _delay * FrameTimer::FramesPerSecond;
47
48 Explosion::Create(_levelHandler, Vector3i((std::int32_t)_pos.X, (std::int32_t)_pos.Y, _renderer.layer() - 2), Explosion::Type::Generator);
49 }
50 return true;
51 }
52
53 return ActorBase::OnHandleCollision(std::move(other));
54 }
55
56 void AirboardGenerator::Preload(const ActorActivationDetails& details)
57 {
58 PreloadMetadataAsync("Object/Airboard"_s);
59 }
60 }