summaryrefslogtreecommitdiff
path: root/src/animatedsprite.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-19 21:24:36 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-19 21:24:36 +0000
commit7ac7d0e030464f744546b4e6183a7242f640d5d3 (patch)
treef19831b29511d46e8aba45ace6017c8e6afe815b /src/animatedsprite.h
parentb7cfcffd7a156e19dfa9882d67426f4fa6edef57 (diff)
downloadmana-7ac7d0e030464f744546b4e6183a7242f640d5d3.tar.gz
mana-7ac7d0e030464f744546b4e6183a7242f640d5d3.tar.bz2
mana-7ac7d0e030464f744546b4e6183a7242f640d5d3.tar.xz
mana-7ac7d0e030464f744546b4e6183a7242f640d5d3.zip
Separated sprite definition from playback.
Diffstat (limited to 'src/animatedsprite.h')
-rw-r--r--src/animatedsprite.h115
1 files changed, 27 insertions, 88 deletions
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index 721a2824..e5a435f9 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -24,55 +24,34 @@
#ifndef _TMW_ANIMATEDSPRITE_H
#define _TMW_ANIMATEDSPRITE_H
+#include "resources/spritedef.h"
+
#include <map>
#include <string>
-#include <SDL_types.h>
-class Action;
class Graphics;
-class Spriteset;
struct AnimationPhase;
-enum SpriteAction
-{
- ACTION_DEFAULT = 0,
- ACTION_STAND,
- ACTION_WALK,
- ACTION_RUN,
- ACTION_ATTACK,
- ACTION_ATTACK_SWING,
- ACTION_ATTACK_STAB,
- ACTION_ATTACK_BOW,
- ACTION_ATTACK_THROW,
- ACTION_CAST_MAGIC,
- ACTION_USE_ITEM,
- ACTION_SIT,
- ACTION_SLEEP,
- ACTION_HURT,
- ACTION_DEAD,
- ACTION_INVALID
-};
-
-enum SpriteDirection
-{
- DIRECTION_DEFAULT = 0,
- DIRECTION_DOWN,
- DIRECTION_UP,
- DIRECTION_LEFT,
- DIRECTION_RIGHT,
- DIRECTION_INVALID
-};
-
/**
- * Defines a class to load an animation.
+ * Animates a sprite by adding playback state.
*/
class AnimatedSprite
{
public:
/**
* Constructor.
+ * @param sprite the sprite to animate
*/
- AnimatedSprite(const std::string& animationFile, int variant);
+ AnimatedSprite(SpriteDef *sprite);
+
+ /**
+ * A convenience constructor, which will request the sprite to animate
+ * from the resource manager.
+ *
+ * @param filename the file of the sprite to animate
+ * @param variant the sprite variant
+ */
+ AnimatedSprite(const std::string& filename, int variant);
/**
* Destructor.
@@ -80,8 +59,7 @@ class AnimatedSprite
~AnimatedSprite();
/**
- * Resets the animated sprite. This is used to synchronize several
- * animated sprites.
+ * Resets the animated sprite.
*/
void
reset();
@@ -104,67 +82,28 @@ class AnimatedSprite
* pixels.
*/
bool
- draw(Graphics* graphics, Sint32 posX, Sint32 posY) const;
-
- /**
- * Returns the width in pixels of the current animation phase.
- */
- int
- getWidth() const;
-
- /**
- * Returns the height in pixels of the current animation phase.
- */
- int
- getHeight() const;
+ draw(Graphics* graphics, int posX, int posY) const;
/**
* Sets the direction.
*/
void
- setDirection(SpriteDirection direction)
- {
- mDirection = direction;
- }
+ setDirection(SpriteDirection direction);
private:
- /**
- * When there are no animations defined for the action "complete", its
- * animations become a copy of those of the action "with".
- */
- void
- substituteAction(SpriteAction complete, SpriteAction with);
-
- /**
- * Returns the current animation frame.
- */
- const AnimationPhase*
- getCurrentPhase() const;
-
- /**
- * Converts a string into a SpriteAction enum.
- */
- static SpriteAction
- makeSpriteAction(const std::string &action);
-
- /**
- * Converts a string into a SpriteDirection enum.
- */
- static SpriteDirection
- makeSpriteDirection(const std::string &direction);
-
+ bool
+ updateCurrentAnimation(unsigned int dt);
- typedef std::map<std::string, Spriteset*> Spritesets;
- typedef Spritesets::iterator SpritesetIterator;
+ SpriteDirection mDirection; /**< The sprite direction. */
+ int mLastTime; /**< The last time update was called. */
- typedef std::map<SpriteAction, Action*> Actions;
- typedef Actions::iterator ActionIterator;
+ unsigned int mFrameIndex; /**< The index of the current frame. */
+ unsigned int mFrameTime; /**< The time since start of frame. */
- Spritesets mSpritesets;
- Actions mActions;
- Action *mAction;
- SpriteDirection mDirection;
- int mLastTime;
+ SpriteDef *mSprite; /**< The sprite definition. */
+ Action *mAction; /**< The currently active action. */
+ Animation *mAnimation; /**< The currently active animation. */
+ AnimationPhase *mFrame; /**< The currently active frame. */
};
#endif