Debian Codegraph @

Sources/Jazz2/Actors/Environment/Checkpoint.cpp

raw
1 #include "Checkpoint.h"
2 #include "../../ILevelHandler.h"
3 #include "../../Events/EventMap.h"
4 #include "../Player.h"
5
6 namespace Jazz2::Actors::Environment
7 {
8 Checkpoint::Checkpoint()
9 : _activated(false)
10 {
11 }
12
13 void Checkpoint::Preload(const ActorActivationDetails& details)
14 {
15 std::uint8_t theme = details.Params[0];
16 switch (theme) {
17 case 0:
18 default:
19 PreloadMetadataAsync("Object/Checkpoint"_s);
20 break;
21 case 1: // Xmas
22 PreloadMetadataAsync("Object/CheckpointXmas"_s);
23 break;
24 }
25 }
26
27 Task<bool> Checkpoint::OnActivatedAsync(const ActorActivationDetails& details)
28 {
29 SetState(ActorState::CanBeFrozen, false);
30
31 _theme = details.Params[0];
32 _activated = (details.Params[1] != 0);
33
34 switch (_theme) {
35 case 0:
36 default:
37 async_await RequestMetadataAsync("Object/Checkpoint"_s);
38 break;
39 case 1: // Xmas
40 async_await RequestMetadataAsync("Object/CheckpointXmas"_s);
41 break;
42 }
43
44 _renderer.setLayer(_renderer.layer() - 40);
45 SetAnimation((AnimState)(_activated ? 1 : 0));
46
47 if (GetState(ActorState::ApplyGravitation)) {
48 OnUpdateHitbox();
49
50 // Apply instant gravitation
51 std::int32_t i = 10;
52 while (i-- > 0 && MoveInstantly(Vector2f(0.0f, 4.0f), MoveType::Relative)) {
53 // Nothing to do...
54 }
55 while (i-- > 0 && MoveInstantly(Vector2f(0.0f, 1.0f), MoveType::Relative)) {
56 // Nothing to do...
57 }
58 }
59
60 async_return true;
61 }
62
63 void Checkpoint::OnUpdateHitbox()
64 {
65 UpdateHitbox(20, 20);
66 }
67
68 bool Checkpoint::OnHandleCollision(std::shared_ptr<ActorBase> other)
69 {
70 if (_activated) {
71 return true;
72 }
73
74 if (auto* player = runtime_cast<Player>(other.get())) {
75 _activated = true;
76
77 SetAnimation((AnimState)1);
78 SetTransition(AnimState::TransitionActivate, false);
79
80 PlaySfx("TransitionActivate"_s);
81
82 // Deactivate event in map
83 std::uint8_t playerParams[16] = { _theme, 1 };
84 _levelHandler->EventMap()->StoreTileEvent(_originTile.X, _originTile.Y, EventType::Checkpoint, ActorState::None, playerParams);
85
86 _levelHandler->SetCheckpoint(player, Vector2f(_pos.X, _pos.Y));
87 return true;
88 }
89
90 return false;
91 }
92 }