Skip to content

Commit

Permalink
Refactor animation count
Browse files Browse the repository at this point in the history
Redo the logic to make Player EasyRPG#663 and Test case 32 pass
  • Loading branch information
fmatthew5876 committed Mar 4, 2019
1 parent fe2ad54 commit e34f263
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
27 changes: 12 additions & 15 deletions src/game_character.cpp
Expand Up @@ -205,11 +205,11 @@ void Game_Character::UpdateAnimation(bool was_moving) {
if (IsSpinning()) {
const auto limit = spin_limits[step_idx];

if (GetAnimCount() >= limit) {
IncAnimCount();

if (GetAnimCount() > limit) {
SetSpriteDirection((GetSpriteDirection() + 1) % 4);
SetAnimCount(0);
} else {
IncAnimCount();
}
return;
}
Expand All @@ -224,21 +224,18 @@ void Game_Character::UpdateAnimation(bool was_moving) {
const auto stationary_limit = stationary_limits[step_idx];
const auto continuous_limit = continuous_limits[step_idx];

if (GetAnimCount() >= continuous_limit) {
IncAnimFrame();
return;
if (IsContinuous()
|| was_moving
|| data()->anim_frame == 0 || data()->anim_frame == 2
|| GetAnimCount() < stationary_limit) {
IncAnimCount();
}

if (GetAnimCount() >= stationary_limit) {
if (was_moving) {
IncAnimFrame();
return;
} else if (!IsContinuous() && (data()->anim_frame == 1 || data()->anim_frame == 3)) {
return;
}
if (GetAnimCount() > continuous_limit
|| (was_moving && GetAnimCount() > stationary_limit)) {
IncAnimFrame();
return;
}

IncAnimCount();
}

void Game_Character::UpdateJump() {
Expand Down
12 changes: 6 additions & 6 deletions src/game_vehicle.cpp
Expand Up @@ -265,10 +265,10 @@ void Game_Vehicle::UpdateAnimationAirship() {
if (IsAboard()) {
const auto limit = 11;

if (GetAnimCount() >= limit) {
IncAnimCount();

if (GetAnimCount() > limit) {
IncAnimFrame();
} else {
IncAnimCount();
}
} else {
ResetAnimation();
Expand All @@ -278,10 +278,10 @@ void Game_Vehicle::UpdateAnimationAirship() {
void Game_Vehicle::UpdateAnimationShip() {
const auto limit = 15;

if (GetAnimCount() >= limit) {
IncAnimCount();

if (GetAnimCount() > limit) {
IncAnimFrame();
} else {
IncAnimCount();
}
}

Expand Down

0 comments on commit e34f263

Please sign in to comment.