summaryrefslogtreecommitdiff
path: root/src/animatedsprite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/animatedsprite.cpp')
-rw-r--r--src/animatedsprite.cpp69
1 files changed, 58 insertions, 11 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index b9946fb1d..1069bcf47 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -142,30 +142,77 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
mFrameTime += time;
- while (mFrameTime > static_cast<unsigned>(mFrame->delay)
- && mFrame->delay > 0)
+ while ((mFrameTime > static_cast<unsigned>(mFrame->delay)
+ && mFrame->delay > 0) || mFrame->type != Frame::ANIMATION)
{
+ bool fail(true);
mFrameTime -= static_cast<unsigned>(mFrame->delay);
mFrameIndex++;
- if (mFrameIndex == mAnimation->getLength())
+ if (mFrameIndex >= mAnimation->getLength())
mFrameIndex = 0;
mFrame = mAnimation->getFrame(mFrameIndex);
- if (Animation::isTerminator(*mFrame))
+ if (mFrame->type == Frame::LABEL && !mFrame->nextAction.empty())
{
- mAnimation = 0;
- mFrame = 0;
- return false;
+ fail = true;
+ }
+ else if (mFrame->type == Frame::GOTO && !mFrame->nextAction.empty())
+ {
+ if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand)
+ {
+ for (int i = 0; i < mAnimation->getLength(); i ++)
+ {
+ Frame *frame = mAnimation->getFrame(i);
+ if (frame->type == Frame::LABEL
+ && mFrame->nextAction == frame->nextAction)
+ {
+ mFrameTime = 0;
+ mFrameIndex = i;
+ if (mFrameIndex >= mAnimation->getLength())
+ mFrameIndex = 0;
+
+ mFrame = mAnimation->getFrame(mFrameIndex);
+
+ fail = true;
+ break;
+ }
+ }
+ }
+ }
+ else if (mFrame->type == Frame::JUMP && !mFrame->nextAction.empty())
+ {
+ if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand)
+ {
+ play(mFrame->nextAction);
+ return true;
+ }
+ }
+ else if (Animation::isTerminator(*mFrame))
+ {
+ if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand)
+ {
+ mAnimation = 0;
+ mFrame = 0;
+ return false;
+ }
}
- if (mFrame->type == Frame::JUMP && !mFrame->nextAction.empty())
+ else
{
- play(mFrame->nextAction);
- return true;
+ if (mFrame->rand == 100 || mFrameIndex >= mAnimation->getLength())
+ {
+ fail = false;
+ }
+ else
+ {
+ if (rand() % 100 <= mFrame->rand)
+ fail = false;
+ }
}
+ if (fail)
+ mFrameTime = mFrame->delay + 1;
}
-
return true;
}