diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-05 00:21:02 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-05 01:04:15 +0300 |
commit | a498132aa32be5fdf8d4227a7332016fc90ed87d (patch) | |
tree | 2a25422158248717df594e7d5e6058303b06cbcb /src/being.cpp | |
parent | faeaa157b1abada82243b8dc508201aa17db1df2 (diff) | |
download | manaplus-a498132aa32be5fdf8d4227a7332016fc90ed87d.tar.gz manaplus-a498132aa32be5fdf8d4227a7332016fc90ed87d.tar.bz2 manaplus-a498132aa32be5fdf8d4227a7332016fc90ed87d.tar.xz manaplus-a498132aa32be5fdf8d4227a7332016fc90ed87d.zip |
add animation effect to being.
can be used for now from effects.xml with attribute "sprite".
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/being.cpp b/src/being.cpp index 4e26e84a6..4243c5a6f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -205,6 +205,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype, mEmotionSprite(nullptr), mEmotionTime(0), mSpeechTime(0), + mAnimationEffect(nullptr), mAttackSpeed(350), mAction(STAND), mSubType(0xFFFF), @@ -295,6 +296,9 @@ Being::~Being() mDispName = nullptr; delete mText; mText = nullptr; + + delete mAnimationEffect; + mAnimationEffect = nullptr; } void Being::setSubtype(const uint16_t subtype) @@ -1200,6 +1204,8 @@ void Being::setAction(const Action &action, const int attackId) play(currentAction); if (mEmotionSprite) mEmotionSprite->play(currentAction); + if (mAnimationEffect) + mAnimationEffect->play(currentAction); mAction = action; } @@ -1253,6 +1259,8 @@ void Being::setDirection(const uint8_t direction) CompoundSprite::setSpriteDirection(dir); if (mEmotionSprite) mEmotionSprite->setSpriteDirection(dir); + if (mAnimationEffect) + mAnimationEffect->setSpriteDirection(dir); recalcSpritesOrder(); } @@ -1325,8 +1333,19 @@ void Being::logic() mText = nullptr; } + const int time = tick_time * MILLISECONDS_IN_A_TICK; if (mEmotionSprite) - mEmotionSprite->update(tick_time * MILLISECONDS_IN_A_TICK); + mEmotionSprite->update(time); + + if (mAnimationEffect) + { + mAnimationEffect->update(time); + if (mAnimationEffect->isTerminated()) + { + delete mAnimationEffect; + mAnimationEffect = nullptr; + } + } int frameCount = static_cast<int>(getFrameCount()); #ifdef MANASERV_SUPPORT @@ -1495,12 +1514,12 @@ void Being::logic() void Being::drawEmotion(Graphics *const graphics, const int offsetX, const int offsetY) { - if (!mEmotionSprite) - return; - const int px = getPixelX() - offsetX - 16; const int py = getPixelY() - offsetY - 64 - 32; - mEmotionSprite->draw(graphics, px, py); + if (mEmotionSprite) + mEmotionSprite->draw(graphics, px, py); + if (mAnimationEffect) + mAnimationEffect->draw(graphics, px, py); } void Being::drawSpeech(const int offsetX, const int offsetY) @@ -2821,6 +2840,8 @@ void Being::removeSpecialEffect() mChildParticleEffects.removeLocally(mSpecialParticle); mSpecialParticle = nullptr; } + delete mAnimationEffect; + mAnimationEffect = nullptr; } void Being::updateAwayEffect() @@ -2831,6 +2852,13 @@ void Being::updateAwayEffect() removeAfkEffect(); } +void Being::addEffect(const std::string &name) +{ + delete mAnimationEffect; + mAnimationEffect = AnimatedSprite::load( + paths.getStringValue("sprites") + name); +} + BeingEquipBackend::BeingEquipBackend(Being *const being): mBeing(being) { |