| 1 |
#include "Eva.h" |
| 2 |
#include "../../ILevelHandler.h" |
| 3 |
#include "../Player.h" |
| 4 |
|
| 5 |
#include "../../../nCine/Base/Random.h" |
| 6 |
|
| 7 |
namespace Jazz2::Actors::Environment |
| 8 |
{ |
| 9 |
Eva::Eva() |
| 10 |
: _animationTime(0.0f) |
| 11 |
{ |
| 12 |
} |
| 13 |
|
| 14 |
Task<bool> Eva::OnActivatedAsync(const ActorActivationDetails& details) |
| 15 |
{ |
| 16 |
SetState(ActorState::ApplyGravitation, false); |
| 17 |
|
| 18 |
async_await RequestMetadataAsync("Object/Eva"_s); |
| 19 |
|
| 20 |
SetAnimation(AnimState::Idle); |
| 21 |
|
| 22 |
async_return true; |
| 23 |
} |
| 24 |
|
| 25 |
void Eva::OnUpdate(float timeMult) |
| 26 |
{ |
| 27 |
ActorBase::OnUpdate(timeMult); |
| 28 |
|
| 29 |
if (_currentTransition == nullptr) { |
| 30 |
if (_animationTime <= 0.0f) { |
| 31 |
SetTransition(AnimState::TransitionIdleBored, true); |
| 32 |
_animationTime = Random().NextFloat(160.0f, 200.0f); |
| 33 |
} else { |
| 34 |
_animationTime -= timeMult; |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
bool Eva::OnHandleCollision(std::shared_ptr<ActorBase> other) |
| 40 |
{ |
| 41 |
if (auto* player = runtime_cast<Player>(other.get())) { |
| 42 |
if (player->GetPlayerType() == PlayerType::Frog && player->DisableControllable(160.0f)) { |
| 43 |
SetTransition(AnimState::TransitionAttack, false, [this, player]() { |
| 44 |
player->MorphRevert(); |
| 45 |
|
| 46 |
PlaySfx("Kiss"_s, 0.8f); |
| 47 |
SetTransition(AnimState::TransitionAttackEnd, false); |
| 48 |
}); |
| 49 |
} |
| 50 |
return true; |
| 51 |
} |
| 52 |
|
| 53 |
return ActorBase::OnHandleCollision(std::move(other)); |
| 54 |
} |
| 55 |
|
| 56 |
void Eva::Preload(const ActorActivationDetails& details) |
| 57 |
{ |
| 58 |
PreloadMetadataAsync("Object/Eva"_s); |
| 59 |
} |
| 60 |
} |