summaryrefslogtreecommitdiff
path: root/src/animation.cpp
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2006-07-20 11:41:32 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2006-07-20 11:41:32 +0000
commitab3871e98d7fe2f69f0ab99c066f8c7040014731 (patch)
tree30b0d9b316ca702df73d43675fd240a735da9e6a /src/animation.cpp
parentb9d581cf5f7c1439f391d3f4906308f9e40d8012 (diff)
downloadmana-ab3871e98d7fe2f69f0ab99c066f8c7040014731.tar.gz
mana-ab3871e98d7fe2f69f0ab99c066f8c7040014731.tar.bz2
mana-ab3871e98d7fe2f69f0ab99c066f8c7040014731.tar.xz
mana-ab3871e98d7fe2f69f0ab99c066f8c7040014731.zip
Fixed left bow attack animation, made the attack animation stay in sync with attack speed.
Diffstat (limited to 'src/animation.cpp')
-rw-r--r--src/animation.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/animation.cpp b/src/animation.cpp
index 57fb931a..d3fa7ce2 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -91,6 +91,22 @@ Animation::addPhase (int image, unsigned int delay, int offsetX, int offsetY)
iCurrentPhase = mAnimationPhases.begin();
}
+int
+Animation::getLength()
+{
+ std::list<AnimationPhase>::iterator i;
+ int length = 0;
+ if (!mAnimationPhases.empty())
+ {
+ for (i = mAnimationPhases.begin(); i != mAnimationPhases.end(); i++)
+ {
+ length += (*i).delay;
+ }
+ }
+ printf("length: %i\n", length);
+ return length;
+}
+
Action::Action()
:mImageset("")
{
@@ -138,7 +154,7 @@ Action::setAnimation(std::string direction, Animation *animation)
AnimatedSprite::AnimatedSprite(std::string animationFile, int variant):
- mAction("stand"), mDirection("down"), mLastTime(0)
+ mAction("stand"), mDirection("down"), mLastTime(0), mSpeed(1.0f)
{
int variant_num = 0;
int variant_offset = 0;
@@ -211,7 +227,7 @@ AnimatedSprite::AnimatedSprite(std::string animationFile, int variant):
xmlChar *prop = NULL;
READ_PROP(node, prop, "name", name, );
READ_PROP(node, prop, "imageset", imageset, );
-
+
Action *action = new Action();
mActions[name] = action;
action->setImageset(imageset);
@@ -315,6 +331,29 @@ AnimatedSprite::play(std::string action)
mAction = action;
}
mLastTime = 0;
+ mSpeed = 1.0f;
+}
+
+void
+AnimatedSprite::play(std::string action, int time)
+{
+ if (mAction != action)
+ {
+ mAction = action;
+ }
+ mLastTime = 0;
+ int animationLength = 0;
+ Action *nextAction = mActions[mAction];
+ Animation *animation = nextAction->getAnimation(mDirection);
+ animationLength = animation->getLength();
+ if (animationLength)
+ {
+ mSpeed = time / animationLength;
+ }
+ else
+ {
+ mSpeed = 1.0f;
+ }
}
void
@@ -331,7 +370,8 @@ AnimatedSprite::update(int time)
if (time < mLastTime || mLastTime == 0) mLastTime = time;
Action *action = mActions[mAction];
- action->getAnimation(mDirection)->update(time - mLastTime);
+ Animation *animation = action->getAnimation(mDirection);
+ animation->update((unsigned int)((time - mLastTime) / mSpeed));
mLastTime = time;
}