summaryrefslogtreecommitdiff
path: root/src/resources/sprite/animatedsprite.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-19 00:26:10 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-19 01:12:11 +0300
commitd0a53b203f918c24837527e15cdc84c807de49ea (patch)
tree306f20a7c97e9848ef46f18d0b8d1a2c0a3c31f1 /src/resources/sprite/animatedsprite.cpp
parentbacd8cd50129135afb1535756b17e8c61f98eeee (diff)
downloadManaVerse-d0a53b203f918c24837527e15cdc84c807de49ea.tar.gz
ManaVerse-d0a53b203f918c24837527e15cdc84c807de49ea.tar.bz2
ManaVerse-d0a53b203f918c24837527e15cdc84c807de49ea.tar.xz
ManaVerse-d0a53b203f918c24837527e15cdc84c807de49ea.zip
Fix unit tests (add missing random initialisation).
Also fix sprites animation if random number is zero.
Diffstat (limited to 'src/resources/sprite/animatedsprite.cpp')
-rw-r--r--src/resources/sprite/animatedsprite.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
index f0af74f08..4daf6f7f6 100644
--- a/src/resources/sprite/animatedsprite.cpp
+++ b/src/resources/sprite/animatedsprite.cpp
@@ -240,8 +240,9 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
else if (mFrame->type == Frame::GOTO &&
!mFrame->nextAction.empty())
{
- if (mFrame->rand == 100 ||
- mFrame->rand >= mrand() % 100)
+ const int rand = mFrame->rand;
+ if (rand == 100 ||
+ (rand && rand >= mrand() % 100))
{
for (size_t i = 0; i < mAnimation->getLength(); i ++)
{
@@ -272,8 +273,9 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
else if (mFrame->type == Frame::JUMP &&
!mFrame->nextAction.empty())
{
- if (mFrame->rand == 100 ||
- mFrame->rand >= mrand() % 100)
+ const int rand = mFrame->rand;
+ if (rand == 100 ||
+ (rand && rand >= mrand() % 100))
{
play(mFrame->nextAction);
return true;
@@ -283,8 +285,9 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
else if (!mFrame->image &&
mFrame->type == Frame::ANIMATION)
{
- if (mFrame->rand == 100 ||
- mFrame->rand >= mrand() % 100)
+ const int rand = mFrame->rand;
+ if (rand == 100 ||
+ (rand && rand >= mrand() % 100))
{
mAnimation = nullptr;
mFrame = nullptr;
@@ -293,14 +296,15 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
}
else
{
- if (mFrame->rand == 100 || mFrameIndex
- >= CAST_U32(mAnimation->getLength()))
+ const int rand = mFrame->rand;
+ if (rand == 100 ||
+ mFrameIndex >= CAST_U32(mAnimation->getLength()))
{
fail = false;
}
else
{
- if (mrand() % 100 <= mFrame->rand)
+ if (rand && mrand() % 100 <= rand)
fail = false;
}
}