| 1 |
#include "PinballPaddle.h" |
| 2 |
#include "../../ILevelHandler.h" |
| 3 |
#include "../Player.h" |
| 4 |
|
| 5 |
namespace Jazz2::Actors::Solid |
| 6 |
{ |
| 7 |
PinballPaddle::PinballPaddle() |
| 8 |
: _cooldown(0.0f) |
| 9 |
{ |
| 10 |
} |
| 11 |
|
| 12 |
void PinballPaddle::Preload(const ActorActivationDetails& details) |
| 13 |
{ |
| 14 |
PreloadMetadataAsync("Object/PinballPaddle"_s); |
| 15 |
} |
| 16 |
|
| 17 |
Task<bool> PinballPaddle::OnActivatedAsync(const ActorActivationDetails& details) |
| 18 |
{ |
| 19 |
bool facingLeft = (details.Params[0] != 0); |
| 20 |
|
| 21 |
SetState(ActorState::CollideWithTileset | ActorState::IsSolidObject | ActorState::ApplyGravitation, false); |
| 22 |
|
| 23 |
async_await RequestMetadataAsync("Object/PinballPaddle"_s); |
| 24 |
|
| 25 |
SetFacingLeft(facingLeft); |
| 26 |
SetAnimation(AnimState::Idle); |
| 27 |
|
| 28 |
async_return true; |
| 29 |
} |
| 30 |
|
| 31 |
void PinballPaddle::OnUpdate(float timeMult) |
| 32 |
{ |
| 33 |
if (_frozenTimeLeft > 0.0f) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if (_cooldown <= 0.0f) { |
| 38 |
_levelHandler->FindCollisionActorsByRadius(_pos.X, _pos.Y, 30.0f, [this](ActorBase* actor) { |
| 39 |
if (auto* player = runtime_cast<Player>(actor)) { |
| 40 |
Vector2f playerPos = player->GetPos(); |
| 41 |
if (playerPos.Y > _pos.Y - 26.0f && playerPos.Y < _pos.Y + 10.0f) { |
| 42 |
_cooldown = 10.0f; |
| 43 |
|
| 44 |
SetTransition(AnimState::TransitionActivate, false); |
| 45 |
PlaySfx("Hit"_s, 0.6f, 0.4f); |
| 46 |
|
| 47 |
float mult = (playerPos.X - _pos.X) / _currentAnimation->Base->FrameDimensions.X; |
| 48 |
if (IsFacingLeft()) { |
| 49 |
mult = 1.0f - mult; |
| 50 |
} |
| 51 |
mult = std::clamp(0.2f + mult * 1.6f, 0.4f, 1.0f); |
| 52 |
|
| 53 |
float forceY = 1.9f * mult; |
| 54 |
if (!_levelHandler->IsReforged()) { |
| 55 |
forceY *= 0.85f; |
| 56 |
} |
| 57 |
|
| 58 |
player->_speed.X = 0.0f; |
| 59 |
player->_speed.Y = (_levelHandler->IsReforged() ? -1.0f : -0.7f); |
| 60 |
|
| 61 |
if (player->_activeModifier == Player::Modifier::None) { |
| 62 |
if (player->_copterFramesLeft > 1.0f) { |
| 63 |
player->_copterFramesLeft = 1.0f; |
| 64 |
} |
| 65 |
|
| 66 |
player->_externalForce.Y -= forceY; |
| 67 |
player->_externalForceCooldown = 10.0f; |
| 68 |
player->_controllable = true; |
| 69 |
player->SetState(ActorState::CanJump, false); |
| 70 |
player->EndDamagingMove(); |
| 71 |
} |
| 72 |
|
| 73 |
// TODO: Check this |
| 74 |
player->AddScore(500); |
| 75 |
} |
| 76 |
} |
| 77 |
return true; |
| 78 |
}); |
| 79 |
} else { |
| 80 |
_cooldown -= timeMult; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
void PinballPaddle::OnUpdateHitbox() |
| 85 |
{ |
| 86 |
if (_currentAnimation != nullptr) { |
| 87 |
AABBInner = AABBf( |
| 88 |
_pos.X - _currentAnimation->Base->FrameDimensions.X * (IsFacingLeft() ? 0.7f : 0.3f), |
| 89 |
_pos.Y - _currentAnimation->Base->FrameDimensions.Y * 0.1f, |
| 90 |
_pos.X + _currentAnimation->Base->FrameDimensions.X * (IsFacingLeft() ? 0.3f : 0.7f), |
| 91 |
_pos.Y + _currentAnimation->Base->FrameDimensions.Y * 0.3f |
| 92 |
); |
| 93 |
} |
| 94 |
} |
| 95 |
} |