summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2006-09-20 23:34:11 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2006-09-20 23:34:11 +0000
commit073d6ba7ad9f4052dcefd0fc64fd705b0e9c8f79 (patch)
tree1838ff9e6a2c54519f2b61af8d54388f2feabfde /src
parent0d2c09435711a5bcb4dfbd7d7900de6c415361ee (diff)
downloadmana-073d6ba7ad9f4052dcefd0fc64fd705b0e9c8f79.tar.gz
mana-073d6ba7ad9f4052dcefd0fc64fd705b0e9c8f79.tar.bz2
mana-073d6ba7ad9f4052dcefd0fc64fd705b0e9c8f79.tar.xz
mana-073d6ba7ad9f4052dcefd0fc64fd705b0e9c8f79.zip
tweaks at the animation system (mostly about fixing the looping attack animations of the monsters)
Diffstat (limited to 'src')
-rw-r--r--src/animatedsprite.cpp26
-rw-r--r--src/animatedsprite.h5
-rw-r--r--src/animation.cpp33
-rw-r--r--src/animation.h16
-rw-r--r--src/being.cpp25
5 files changed, 74 insertions, 31 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 36851366..e7439644 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -176,6 +176,10 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
start++;
}
}
+ else if (xmlStrEqual(phaseNode->name, BAD_CAST "end"))
+ {
+ animation->addTerminator();
+ };
} // for phaseNode
} // for animationNode
} // if "<imageset>" else if "<action>"
@@ -268,7 +272,7 @@ AnimatedSprite::reset()
}
void
-AnimatedSprite::play(SpriteAction action, int time)
+AnimatedSprite::play(SpriteAction action)
{
ActionIterator i = mActions.find(action);
@@ -282,23 +286,14 @@ AnimatedSprite::play(SpriteAction action, int time)
if (mAction != i->second)
{
mAction = i->second;
- mLastTime = 0;
- }
-
- if (!mAction || !time)
- mSpeed = 1.0f;
- else {
- Animation* animation= mAction->getAnimation(mDirection);
- if (animation) {
- int animationLength = animation->getLength();
- mSpeed = (float) animationLength / time;
- }
+ //mAction->reset();
}
}
void
AnimatedSprite::update(int time)
{
+ bool notFinished = true;
// Avoid freaking out at first frame or when tick_time overflows
if (time < mLastTime || mLastTime == 0)
mLastTime = time;
@@ -308,9 +303,14 @@ AnimatedSprite::update(int time)
{
Animation *animation = mAction->getAnimation(mDirection);
if (animation != NULL) {
- animation->update((unsigned int)((time - mLastTime) * mSpeed));}
+ notFinished = animation->update((unsigned int)(time - mLastTime));}
mLastTime = time;
}
+
+ if (!notFinished)
+ {
+ play(ACTION_STAND);
+ }
}
bool
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index ea661d94..e87a9885 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -88,11 +88,10 @@ class AnimatedSprite
reset();
/**
- * Plays an action using the current direction that will have a
- * duration of the specified time, 0 means default.
+ * Plays an action using the current direction
*/
void
- play(SpriteAction action, int time = 0);
+ play(SpriteAction action);
/**
* Inform the animation of the passed time so that it can output the
diff --git a/src/animation.cpp b/src/animation.cpp
index c1b27ebd..98a4abb8 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -39,45 +39,68 @@ Animation::reset()
iCurrentPhase = mAnimationPhases.begin();
}
-void
+
+bool
Animation::update(unsigned int time)
{
mTime += time;
if (mAnimationPhases.empty())
- return;
+ return true;
+ if (isTerminator(*iCurrentPhase))
+ return false;
unsigned int delay = iCurrentPhase->delay;
- if (!delay)
- return;
while (mTime > delay)
{
+ if (!delay)
+ return true;
mTime -= delay;
iCurrentPhase++;
if (iCurrentPhase == mAnimationPhases.end())
{
iCurrentPhase = mAnimationPhases.begin();
}
+ if (isTerminator(*iCurrentPhase))
+ return false;
+ delay = iCurrentPhase->delay;
}
+ return true;
}
+
int
Animation::getCurrentPhase() const
{
return mAnimationPhases.empty() ? -1 : iCurrentPhase->image;
}
+
void
Animation::addPhase(int image, unsigned int delay, int offsetX, int offsetY)
{
//add new phase to animation list
- AnimationPhase newPhase = { image, delay, offsetX, offsetY };
+ AnimationPhase newPhase = { image, delay, offsetX, offsetY};
mAnimationPhases.push_back(newPhase);
//reset animation circle
iCurrentPhase = mAnimationPhases.begin();
}
+void
+Animation::addTerminator()
+{
+ AnimationPhase terminator = { -1, 0, 0, 0};
+ mAnimationPhases.push_back(terminator);
+ iCurrentPhase = mAnimationPhases.begin();
+}
+
+bool
+Animation::isTerminator(AnimationPhase candidate)
+{
+ return (candidate.image < 0);
+}
+
int
Animation::getLength()
{
diff --git a/src/animation.h b/src/animation.h
index 60dcd287..605d8cb1 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -61,10 +61,25 @@ class Animation
void
reset();
+ /**
+ * Appends a new animation at the end of the sequence
+ */
void
addPhase(int image, unsigned int delay, int offsetX, int offsetY);
+ /**
+ * Appends an animation terminator that states that the animation
+ * should not loop
+ */
void
+ addTerminator();
+
+ /**
+ * Updates animation phase.
+ * true indicates a still running animation while false indicates a
+ * finished animation
+ */
+ bool
update(unsigned int time);
int
@@ -89,6 +104,7 @@ class Animation
getLength();
protected:
+ static bool isTerminator(AnimationPhase);
std::list<AnimationPhase> mAnimationPhases;
std::list<AnimationPhase>::iterator iCurrentPhase;
unsigned int mTime;
diff --git a/src/being.cpp b/src/being.cpp
index 1ca8929a..e7b27f43 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -190,10 +190,24 @@ Being::setAction(Uint8 action)
currentAction = ACTION_ATTACK;
break;
}
+ for (int i = 0; i < VECTOREND_SPRITE; i++)
+ {
+ if (mSprites[i])
+ {
+ mSprites[i]->reset();
+ }
+ }
};
break;
case MONSTER_ATTACK:
currentAction = ACTION_ATTACK;
+ for (int i = 0; i < VECTOREND_SPRITE; i++)
+ {
+ if (mSprites[i])
+ {
+ mSprites[i]->reset();
+ }
+ }
break;
case DEAD:
currentAction = ACTION_DEAD;
@@ -205,16 +219,7 @@ Being::setAction(Uint8 action)
for (int i = 0; i < VECTOREND_SPRITE; i++)
{
- if (!mSprites[i])
- continue;
-
- if (currentAction == ACTION_ATTACK ||
- currentAction == ACTION_ATTACK_STAB ||
- currentAction == ACTION_ATTACK_BOW)
- {
- mSprites[i]->play(currentAction, mAttackSpeed);
- }
- else
+ if (mSprites[i])
{
mSprites[i]->play(currentAction);
}