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()];
}
[[nodiscard]] bool isLastFrame() const
{
return currentFrame >= (numberOfFrames - 1);
}
/**
* @brief Calculates the Frame to use for the Animation 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.currentFrame >= player._pWFrames - 1) {
// Update the player's tile position
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;
}
if (!player.AnimInfo.isLastFrame()) {
// We didn't reach new tile so update player's "sub-tile" position
ChangeOffset(player);
return false;
}
// Update the coordinates for lighting and vision entries for the player
if (leveltype != DTYPE_TOWN) {
ChangeLightXY(player._plid, player.position.tile);
ChangeVisionXY(player._pvid, player.position.tile);
}
// We reached the new tile -> update the player's tile position
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;
}
if (player.walkpath[0] != WALK_NONE) {
StartWalkStand(player);
} else {
StartStand(player, player.tempDirection);
}
// Update the coordinates for lighting and vision entries for the player
if (leveltype != DTYPE_TOWN) {
ChangeLightXY(player._plid, player.position.tile);
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
if (leveltype != DTYPE_TOWN) {
ChangeLightOffset(player._plid, { 0, 0 });
}
ClearStateVariables(player);
AutoPickup(player);
return true;
} // We didn't reach new tile so update player's "sub-tile" position
ChangeOffset(player);
return false;
// Reset the "sub-tile" position of the player's light entry to 0
if (leveltype != DTYPE_TOWN) {
ChangeLightOffset(player._plid, { 0, 0 });
}
AutoPickup(player);
return true;
}
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);
ClearStateVariables(player);
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);
ClearStateVariables(player);
return true;
@ -1146,7 +1146,7 @@ void DamageParryItem(Player &player)
bool DoBlock(Player &player)
{
if (player.AnimInfo.currentFrame >= player._pBFrames - 1) {
if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir);
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);
ClearStateVariables(player);
return true;
@ -1228,7 +1228,7 @@ bool DoSpell(Player &player)
bool DoGotHit(Player &player)
{
if (player.AnimInfo.currentFrame >= player._pHFrames - 1) {
if (player.AnimInfo.isLastFrame()) {
StartStand(player, player._pdir);
ClearStateVariables(player);
if (!FlipCoin(4)) {

Loading…
Cancel
Save