summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-05 00:21:02 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-05 01:04:15 +0300
commita498132aa32be5fdf8d4227a7332016fc90ed87d (patch)
tree2a25422158248717df594e7d5e6058303b06cbcb
parentfaeaa157b1abada82243b8dc508201aa17db1df2 (diff)
downloadmanaverse-a498132aa32be5fdf8d4227a7332016fc90ed87d.tar.gz
manaverse-a498132aa32be5fdf8d4227a7332016fc90ed87d.tar.bz2
manaverse-a498132aa32be5fdf8d4227a7332016fc90ed87d.tar.xz
manaverse-a498132aa32be5fdf8d4227a7332016fc90ed87d.zip
add animation effect to being.
can be used for now from effects.xml with attribute "sprite".
-rw-r--r--src/animatedsprite.cpp4
-rw-r--r--src/animatedsprite.h4
-rw-r--r--src/being.cpp38
-rw-r--r--src/being.h4
-rw-r--r--src/effectmanager.cpp38
5 files changed, 67 insertions, 21 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 0842186fc..d60107b15 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -46,7 +46,8 @@ AnimatedSprite::AnimatedSprite(SpriteDef *const sprite):
mFrame(nullptr),
mNumber(100),
mNumber1(100),
- mDelayLoad(nullptr)
+ mDelayLoad(nullptr),
+ mTerminated(false)
{
mAlpha = 1.0f;
@@ -174,6 +175,7 @@ bool AnimatedSprite::update(const int time)
{
// Animation finished, reset to default
play(SpriteAction::STAND);
+ mTerminated = true;
}
// Make sure something actually changed
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index 054fcdb68..2d8a55f26 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -101,6 +101,9 @@ class AnimatedSprite final : public Sprite
void setSprite(SpriteDef *const sprite)
{ mSprite = sprite; }
+ bool isTerminated() const
+ { return mTerminated; }
+
static void setEnableCache(const bool b)
{ mEnableCache = b; }
@@ -122,6 +125,7 @@ class AnimatedSprite final : public Sprite
unsigned mNumber;
unsigned mNumber1;
AnimationDelayLoad *mDelayLoad;
+ bool mTerminated;
static bool mEnableCache;
};
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)
{
diff --git a/src/being.h b/src/being.h
index 88fcae859..7c8fcb173 100644
--- a/src/being.h
+++ b/src/being.h
@@ -861,6 +861,8 @@ class Being : public ActorSprite, public ConfigListener
void removeSpecialEffect();
+ void addEffect(const std::string &name);
+
static uint8_t genderToInt(const Gender sex) A_WARN_UNUSED;
static Gender intToGender(uint8_t sex) A_WARN_UNUSED;
@@ -890,6 +892,8 @@ class Being : public ActorSprite, public ConfigListener
/** Time until the last speech sentence disappears */
int mSpeechTime;
+ AnimatedSprite* mAnimationEffect;
+
int mAttackSpeed; /**< Attack speed */
Action mAction; /**< Action the being is performing */
diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp
index f7e1ccbaa..ac4f80afc 100644
--- a/src/effectmanager.cpp
+++ b/src/effectmanager.cpp
@@ -70,17 +70,20 @@ bool EffectManager::trigger(const int id, Being *const being,
bool rValue = false;
FOR_EACH (std::vector<EffectDescription>::const_iterator, i, mEffects)
{
- if ((*i).id == id)
+ const EffectDescription &effect = *i;
+ if (effect.id == id)
{
rValue = true;
- if (!(*i).gfx.empty())
+ if (!effect.gfx.empty())
{
Particle *const selfFX = particleEngine->addEffect(
- (*i).gfx, 0, 0, rotation);
+ effect.gfx, 0, 0, rotation);
being->controlParticle(selfFX);
}
- if (!(*i).sfx.empty())
- soundManager.playSfx((*i).sfx);
+ if (!effect.sfx.empty())
+ soundManager.playSfx(effect.sfx);
+ if (!effect.sprite.empty())
+ being->addEffect(effect.sprite);
break;
}
}
@@ -96,16 +99,19 @@ Particle *EffectManager::triggerReturn(const int id, Being *const being,
Particle *rValue = nullptr;
FOR_EACH (std::vector<EffectDescription>::const_iterator, i, mEffects)
{
- if ((*i).id == id)
+ const EffectDescription &effect = *i;
+ if (effect.id == id)
{
- if (!(*i).gfx.empty())
+ if (!effect.gfx.empty())
{
rValue = particleEngine->addEffect(
- (*i).gfx, 0, 0, rotation);
+ effect.gfx, 0, 0, rotation);
being->controlParticle(rValue);
}
- if (!(*i).sfx.empty())
- soundManager.playSfx((*i).sfx);
+ if (!effect.sfx.empty())
+ soundManager.playSfx(effect.sfx);
+ if (!effect.sprite.empty())
+ being->addEffect(effect.sprite);
break;
}
}
@@ -121,13 +127,15 @@ bool EffectManager::trigger(const int id, const int x, const int y,
bool rValue = false;
FOR_EACH (std::vector<EffectDescription>::const_iterator, i, mEffects)
{
- if ((*i).id == id)
+ const EffectDescription &effect = *i;
+ if (effect.id == id)
{
rValue = true;
- if (!(*i).gfx.empty() && particleEngine)
- particleEngine->addEffect((*i).gfx, x, y, rotation);
- if (!(*i).sfx.empty())
- soundManager.playSfx((*i).sfx);
+ if (!effect.gfx.empty() && particleEngine)
+ particleEngine->addEffect(effect.gfx, x, y, rotation);
+ if (!effect.sfx.empty())
+ soundManager.playSfx(effect.sfx);
+ // TODO add sprite effect to position
break;
}
}