summaryrefslogtreecommitdiff
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
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.
-rw-r--r--ChangeLog4
-rw-r--r--src/animation.cpp46
-rw-r--r--src/animation.h14
-rw-r--r--src/being.cpp16
4 files changed, 71 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 892e59de..0fd653e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,10 @@
* src/tmw.rc, The Mana World.dev, tmw.cbp: Added a resource script to
let both Dev-Cpp and Code::Blocks share the same binary icon and
version infos.
+ * data/graphics/sprites/player_female_base.xml,
+ data/graphics/sprites/player_male_base.xml, src/animation.cpp,
+ src/animation.h, src/being.cpp: Fixed left bow attack animation,
+ made the attack animation stay in sync with attack speed.
2006-07-19 Bjørn Lindeijer <bjorn@lindeijer.nl>
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;
}
diff --git a/src/animation.h b/src/animation.h
index 55f0bc99..7447b7a8 100644
--- a/src/animation.h
+++ b/src/animation.h
@@ -46,14 +46,16 @@ class Animation
public:
Animation();
- void addPhase (int image, unsigned int delay, int offsetX, int offsetY);
+ void addPhase(int image, unsigned int delay, int offsetX, int offsetY);
void update(unsigned int time);
int getCurrentPhase();
- int getOffsetX() { return (*iCurrentPhase).offsetX ; };
- int getOffsetY() { return (*iCurrentPhase).offsetY ; };
+ int getOffsetX() { return (*iCurrentPhase).offsetX; };
+ int getOffsetY() { return (*iCurrentPhase).offsetY; };
+
+ int getLength();
protected:
std::list<AnimationPhase> mAnimationPhases;
@@ -105,6 +107,11 @@ class AnimatedSprite
void play(std::string action);
/**
+ * Plays an action in a specified time.
+ */
+ void play(std::string action, int time);
+
+ /**
* Sets a new action with a new direction.
*/
void play(std::string action, std::string direction);
@@ -155,6 +162,7 @@ class AnimatedSprite
Actions mActions;
std::string mAction, mDirection;
int mLastTime;
+ float mSpeed;
};
#endif
diff --git a/src/being.cpp b/src/being.cpp
index 19d9d916..d34ea43e 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -221,7 +221,19 @@ Being::setAction(Action action)
for (int i = 0; i < VECTOREND_SPRITE; i++)
{
- if (mSprites[i] != NULL) mSprites[i]->play(currentAction);
+ if (mSprites[i] != NULL)
+ {
+ if (currentAction == "attack" ||
+ currentAction == "attack_stab" ||
+ currentAction == "attack_bow")
+ {
+ mSprites[i]->play(currentAction, mAttackSpeed);
+ }
+ else
+ {
+ mSprites[i]->play(currentAction);
+ }
+ }
}
}
mAction = action;
@@ -317,7 +329,6 @@ Being::logic()
{
if (mSprites[i] != NULL)
{
- printf("Draw: %i\n", i);
mSprites[i]->update(tick_time * 10);
}
}
@@ -338,7 +349,6 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY)
if (mSprites[i] != NULL)
{
mSprites[i]->draw(graphics, px, py);
- printf("Draw: %i\n", i);
}
}
}