From 3204ff7bdaccc039b9589b9834091351c933a11e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 18 Nov 2015 18:33:16 +0300 Subject: Fix style in animatedsprite. --- src/animatedsprite.cpp | 48 +++++++++++++++++++++++++++++------------------- src/animatedsprite.h | 4 ++-- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 785a00e7f..cf5b275db 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -116,7 +116,9 @@ AnimatedSprite::~AnimatedSprite() bool AnimatedSprite::reset() { - const bool ret = mFrameIndex !=0 || mFrameTime != 0 || mLastTime != 0; + const bool ret = mFrameIndex !=0 || + mFrameTime != 0 || + mLastTime != 0; mFrameIndex = 0; mFrameTime = 0; @@ -146,7 +148,9 @@ bool AnimatedSprite::play(const std::string &spriteAction) mAction = action; const Animation *const animation = mAction->getAnimation(mDirection); - if (animation && animation != mAnimation && animation->getLength() > 0) + if (animation && + animation != mAnimation && + animation->getLength() > 0) { mAnimation = animation; reset(); @@ -195,9 +199,10 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) mFrameTime += time; - while ((mFrameTime > static_cast(mFrame->delay) - && mFrame->delay > 0) || (mFrame->type != Frame::ANIMATION - && mFrame->type != Frame::PAUSE)) + while ((mFrameTime > static_cast(mFrame->delay) && + mFrame->delay > 0) || + (mFrame->type != Frame::ANIMATION && + mFrame->type != Frame::PAUSE)) { bool fail(true); mFrameTime -= static_cast(mFrame->delay); @@ -216,15 +221,17 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) { fail = false; } - else if (mFrame->type == Frame::GOTO && !mFrame->nextAction.empty()) + else if (mFrame->type == Frame::GOTO && + !mFrame->nextAction.empty()) { - if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand) + if (mFrame->rand == 100 || + mFrame->rand >= rand() % 100) { for (size_t i = 0; i < mAnimation->getLength(); i ++) { const Frame *const frame = &mAnimation->mFrames[i]; - if (frame->type == Frame::LABEL - && mFrame->nextAction == frame->nextAction) + if (frame->type == Frame::LABEL && + mFrame->nextAction == frame->nextAction) { mFrameIndex = static_cast(i); if (mFrameIndex >= static_cast( @@ -245,18 +252,22 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) fail = false; } } - else if (mFrame->type == Frame::JUMP && !mFrame->nextAction.empty()) + else if (mFrame->type == Frame::JUMP && + !mFrame->nextAction.empty()) { - if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand) + if (mFrame->rand == 100 || + mFrame->rand >= rand() % 100) { play(mFrame->nextAction); return true; } } // copy code from Animation::isTerminator(*mFrame) - else if (!mFrame->image && mFrame->type == Frame::ANIMATION) + else if (!mFrame->image && + mFrame->type == Frame::ANIMATION) { - if (mFrame->rand == 100 || rand() % 100 <= mFrame->rand) + if (mFrame->rand == 100 || + mFrame->rand >= rand() % 100) { mAnimation = nullptr; mFrame = nullptr; @@ -288,7 +299,8 @@ bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) } void AnimatedSprite::draw(Graphics *const graphics, - const int posX, const int posY) const + const int posX, + const int posY) const { FUNC_BLOCK("AnimatedSprite::draw", 1) if (!mFrame || !mFrame->image) @@ -313,7 +325,9 @@ bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction) const Animation *const animation = mAction->getAnimation(mDirection); - if (animation && animation != mAnimation && animation->getLength() > 0) + if (animation && + animation != mAnimation && + animation->getLength() > 0) { mAnimation = animation; reset(); @@ -382,10 +396,6 @@ const void *AnimatedSprite::getHash() const { if (mFrame) return mFrame; -// if (mFrame && mFrame->image) -// return mFrame->image; -// if (mAnimation) -// return mAnimation; return this; } diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 5e0f58c76..10e378593 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -68,8 +68,8 @@ class AnimatedSprite final : public Sprite bool update(const int time) override final; void draw(Graphics *const graphics, - const int posX, const int posY) - const override final A_NONNULL(2); + const int posX, + const int posY) const override final A_NONNULL(2); int getWidth() const override final A_WARN_UNUSED; -- cgit v1.2.3-60-g2f50