File: AirboardGenerator.cpp

package info (click to toggle)
jazz2-native 3.5.0-3
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (60 lines) | stat: -rw-r--r-- 1,413 bytes parent folder | download
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
#include "AirboardGenerator.h"
#include "../../ILevelHandler.h"
#include "../Player.h"
#include "../Explosion.h"

#include "../../../nCine/Base/FrameTimer.h"

namespace Jazz2::Actors::Environment
{
	AirboardGenerator::AirboardGenerator()
		: _timeLeft(0.0f), _active(false)
	{
	}

	Task<bool> AirboardGenerator::OnActivatedAsync(const ActorActivationDetails& details)
	{
		_delay = details.Params[0];
		_active = true;

		async_await RequestMetadataAsync("Object/Airboard"_s);

		SetAnimation(AnimState::Default);

		async_return true;
	}

	void AirboardGenerator::OnUpdate(float timeMult)
	{
		if (!_active) {
			if (_timeLeft <= 0.0f) {
				_active = true;
				_renderer.setDrawEnabled(true);
			}

			_timeLeft -= timeMult;
		}
	}

	bool AirboardGenerator::OnHandleCollision(std::shared_ptr<ActorBase> other)
	{
		if (auto* player = runtime_cast<Player>(other.get())) {
			if (_active && player->SetModifier(Player::Modifier::Airboard)) {
				_active = false;
				_renderer.setDrawEnabled(false);

				_timeLeft = _delay * FrameTimer::FramesPerSecond;

				Explosion::Create(_levelHandler, Vector3i((std::int32_t)_pos.X, (std::int32_t)_pos.Y, _renderer.layer() - 2), Explosion::Type::Generator);
			}
			return true;
		}

		return ActorBase::OnHandleCollision(std::move(other));
	}

	void AirboardGenerator::Preload(const ActorActivationDetails& details)
	{
		PreloadMetadataAsync("Object/Airboard"_s);
	}
}