mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Attemts to improve timing of ranged attacks:
- when computing number of steps/frames to display projectile round to nearest instead of rounding down - end projectile animation only *after* last step was shown
This commit is contained in:
@@ -814,7 +814,9 @@ bool CShootingAnimation::init()
|
|||||||
if (attackedStack)
|
if (attackedStack)
|
||||||
{
|
{
|
||||||
double animSpeed = AnimationControls::getProjectileSpeed(); // flight speed of projectile
|
double animSpeed = AnimationControls::getProjectileSpeed(); // flight speed of projectile
|
||||||
spi.lastStep = static_cast<int>(sqrt(static_cast<double>((destPos.x - spi.x) * (destPos.x - spi.x) + (destPos.y - spi.y) * (destPos.y - spi.y))) / animSpeed);
|
double distanceSquared = (destPos.x - spi.x) * (destPos.x - spi.x) + (destPos.y - spi.y) * (destPos.y - spi.y);
|
||||||
|
double distance = sqrt(distanceSquared);
|
||||||
|
spi.lastStep = std::round(distance / animSpeed);
|
||||||
if(spi.lastStep == 0)
|
if(spi.lastStep == 0)
|
||||||
spi.lastStep = 1;
|
spi.lastStep = 1;
|
||||||
spi.dx = (destPos.x - spi.x) / spi.lastStep;
|
spi.dx = (destPos.x - spi.x) / spi.lastStep;
|
||||||
|
@@ -3269,7 +3269,7 @@ void CBattleInterface::showProjectiles(SDL_Surface *to)
|
|||||||
|
|
||||||
// Update projectile
|
// Update projectile
|
||||||
++it->step;
|
++it->step;
|
||||||
if (it->step == it->lastStep)
|
if (it->step > it->lastStep)
|
||||||
{
|
{
|
||||||
toBeDeleted.insert(toBeDeleted.end(), it);
|
toBeDeleted.insert(toBeDeleted.end(), it);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user