Browse Source

Introduce AnimationInfo::isLastFrame and use it instead of _pXYZFrames

pull/5328/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
925e13d22a
  1. 5
      Source/engine/animationinfo.h
  2. 90
      Source/player.cpp

5
Source/engine/animationinfo.h

@ -66,6 +66,11 @@ public:
return (*sprites)[getFrameToUseForRendering()]; return (*sprites)[getFrameToUseForRendering()];
} }
[[nodiscard]] bool isLastFrame() const
{
return currentFrame >= (numberOfFrames - 1);
}
/** /**
* @brief Calculates the Frame to use for the Animation rendering * @brief Calculates the Frame to use for the Animation rendering
* @return The Frame to use for rendering * @return The Frame to use for rendering

90
Source/player.cpp

@ -587,51 +587,51 @@ bool DoWalk(Player &player, int variant)
} }
} }
// Check if we reached new tile if (!player.AnimInfo.isLastFrame()) {
if (player.AnimInfo.currentFrame >= player._pWFrames - 1) { // We didn't reach new tile so update player's "sub-tile" position
ChangeOffset(player);
// Update the player's tile position return false;
switch (variant) { }
case PM_WALK_NORTHWARDS:
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
player.position.tile = player.position.temp;
dPlayer[player.position.tile.x][player.position.tile.y] = player.getId() + 1;
break;
case PM_WALK_SOUTHWARDS:
dPlayer[player.position.temp.x][player.position.temp.y] = 0;
break;
case PM_WALK_SIDEWAYS:
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
player.position.tile = player.position.temp;
// dPlayer is set here for backwards comparability, without it the player would be invisible if loaded from a vanilla save.
dPlayer[player.position.tile.x][player.position.tile.y] = player.getId() + 1;
break;
}
// Update the coordinates for lighting and vision entries for the player // We reached the new tile -> update the player's tile position
if (leveltype != DTYPE_TOWN) { switch (variant) {
ChangeLightXY(player._plid, player.position.tile); case PM_WALK_NORTHWARDS:
ChangeVisionXY(player._pvid, player.position.tile); dPlayer[player.position.tile.x][player.position.tile.y] = 0;
} player.position.tile = player.position.temp;
dPlayer[player.position.tile.x][player.position.tile.y] = player.getId() + 1;
break;
case PM_WALK_SOUTHWARDS:
dPlayer[player.position.temp.x][player.position.temp.y] = 0;
break;
case PM_WALK_SIDEWAYS:
dPlayer[player.position.tile.x][player.position.tile.y] = 0;
player.position.tile = player.position.temp;
// dPlayer is set here for backwards comparability, without it the player would be invisible if loaded from a vanilla save.
dPlayer[player.position.tile.x][player.position.tile.y] = player.getId() + 1;
break;
}
if (player.walkpath[0] != WALK_NONE) { // Update the coordinates for lighting and vision entries for the player
StartWalkStand(player); if (leveltype != DTYPE_TOWN) {
} else { ChangeLightXY(player._plid, player.position.tile);
StartStand(player, player.tempDirection); ChangeVisionXY(player._pvid, player.position.tile);
} }
ClearStateVariables(player); if (player.walkpath[0] != WALK_NONE) {
StartWalkStand(player);
} else {
StartStand(player, player.tempDirection);
}
// Reset the "sub-tile" position of the player's light entry to 0 ClearStateVariables(player);
if (leveltype != DTYPE_TOWN) {
ChangeLightOffset(player._plid, { 0, 0 });
}
AutoPickup(player); // Reset the "sub-tile" position of the player's light entry to 0
return true; if (leveltype != DTYPE_TOWN) {
} // We didn't reach new tile so update player's "sub-tile" position ChangeLightOffset(player._plid, { 0, 0 });
ChangeOffset(player); }
return false;
AutoPickup(player);
return true;
} }
bool WeaponDecay(Player &player, int ii) bool WeaponDecay(Player &player, int ii)
@ -1040,7 +1040,7 @@ bool DoAttack(Player &player)
} }
} }
if (player.AnimInfo.currentFrame == player._pAFrames - 1) { if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir); StartStand(player, player._pdir);
ClearStateVariables(player); ClearStateVariables(player);
return true; return true;
@ -1107,7 +1107,7 @@ bool DoRangeAttack(Player &player)
} }
} }
if (player.AnimInfo.currentFrame >= player._pAFrames - 1) { if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir); StartStand(player, player._pdir);
ClearStateVariables(player); ClearStateVariables(player);
return true; return true;
@ -1146,7 +1146,7 @@ void DamageParryItem(Player &player)
bool DoBlock(Player &player) bool DoBlock(Player &player)
{ {
if (player.AnimInfo.currentFrame >= player._pBFrames - 1) { if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir); StartStand(player, player._pdir);
ClearStateVariables(player); ClearStateVariables(player);
@ -1217,7 +1217,7 @@ bool DoSpell(Player &player)
} }
} }
if (player.AnimInfo.currentFrame >= player._pSFrames - 1) { if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir); StartStand(player, player._pdir);
ClearStateVariables(player); ClearStateVariables(player);
return true; return true;
@ -1228,7 +1228,7 @@ bool DoSpell(Player &player)
bool DoGotHit(Player &player) bool DoGotHit(Player &player)
{ {
if (player.AnimInfo.currentFrame >= player._pHFrames - 1) { if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir); StartStand(player, player._pdir);
ClearStateVariables(player); ClearStateVariables(player);
if (!FlipCoin(4)) { if (!FlipCoin(4)) {

Loading…
Cancel
Save