1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 19:43:06 +01:00

Split off Update{Action,Walking}Animation and use for frozen peeps

This commit is contained in:
Aaron van Geffen
2024-06-29 15:25:40 +02:00
parent ed6bde7d56
commit 0efbf7f5ea
2 changed files with 36 additions and 8 deletions

View File

@@ -428,18 +428,13 @@ std::optional<CoordsXY> Peep::UpdateAction(int16_t& xy_distance)
return UpdateWalkingAction(differenceLoc, xy_distance);
}
const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType);
ActionFrame++;
// If last frame of action
if (ActionFrame >= peepAnimation.frame_offsets.size())
if (!UpdateActionAnimation())
{
ActionSpriteImageOffset = 0;
Action = PeepActionType::Walking;
UpdateCurrentActionSpriteType();
return { { x, y } };
}
ActionSpriteImageOffset = peepAnimation.frame_offsets[ActionFrame];
// Should we throw up, and are we at the frame where sick appears?
auto* guest = As<Guest>();
@@ -451,6 +446,21 @@ std::optional<CoordsXY> Peep::UpdateAction(int16_t& xy_distance)
return { { x, y } };
}
bool Peep::UpdateActionAnimation()
{
const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType);
ActionFrame++;
// If last frame of action
if (ActionFrame >= peepAnimation.frame_offsets.size())
{
return false;
}
ActionSpriteImageOffset = peepAnimation.frame_offsets[ActionFrame];
return true;
}
std::optional<CoordsXY> Peep::UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance)
{
if (!IsActionWalking())
@@ -489,6 +499,13 @@ std::optional<CoordsXY> Peep::UpdateWalkingAction(const CoordsXY& differenceLoc,
CoordsXY loc = { x, y };
loc += walkingOffsetByDirection[nextDirection];
UpdateWalkingAnimation();
return loc;
}
void Peep::UpdateWalkingAnimation()
{
WalkingFrameNum++;
const PeepAnimation& peepAnimation = GetPeepAnimation(SpriteType, ActionSpriteType);
if (WalkingFrameNum >= peepAnimation.frame_offsets.size())
@@ -496,8 +513,6 @@ std::optional<CoordsXY> Peep::UpdateWalkingAction(const CoordsXY& differenceLoc,
WalkingFrameNum = 0;
}
ActionSpriteImageOffset = peepAnimation.frame_offsets[WalkingFrameNum];
return loc;
}
void Peep::ThrowUp()
@@ -958,6 +973,17 @@ void Peep::Update()
{
if (PeepFlags & PEEP_FLAGS_POSITION_FROZEN)
{
if (!(PeepFlags & PEEP_FLAGS_ANIMATION_FROZEN))
{
// This is circumventing other logic, so only update every few ticks
if ((GetGameState().CurrentTicks & 3) == 0)
{
if (IsActionWalking())
UpdateWalkingAnimation();
else
UpdateActionAnimation();
}
}
return;
}

View File

@@ -377,7 +377,9 @@ public: // Peep
void Update();
std::optional<CoordsXY> UpdateAction(int16_t& xy_distance);
std::optional<CoordsXY> UpdateAction();
bool UpdateActionAnimation();
std::optional<CoordsXY> UpdateWalkingAction(const CoordsXY& differenceLoc, int16_t& xy_distance);
void UpdateWalkingAnimation();
void ThrowUp();
void SetState(PeepState new_state);
void Remove();