summaryrefslogtreecommitdiff
path: root/src/animatedsprite.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-13 03:36:00 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-13 03:36:00 +0300
commitc978b7f0d9de1bb6bd84cd299ed80c27c5147927 (patch)
tree8f1edc2be0816693761ba58aa7c7c554040a7db6 /src/animatedsprite.cpp
parentda1b2d8311ca78eccd3e9875598562ce6bf05cab (diff)
downloadplus-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.tar.gz
plus-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.tar.bz2
plus-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.tar.xz
plus-c978b7f0d9de1bb6bd84cd299ed80c27c5147927.zip
Impliment new tags in sprites animations and random condition.
Tags: <label>, <goto>
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;
}