Dragonfly 4.20
A text-based game engine
Animation.h
1///
2/// An animation for a sprite
3///
4
5#ifndef __ANIMATION_H__
6#define __ANIMATION_H__
7
8// System includes.
9#include <string>
10
11// Engine includes.
12#include "Box.h"
13#include "Sprite.h"
14
15namespace df {
16
17class Animation {
18
19 private:
20 Sprite *m_p_sprite; ///< Sprite associated with Animation.
21 int m_index; ///< Current index frame for Sprite.
22 int m_slowdown_count; ///< Slowdown counter (-1 means stop).
23 std::string m_name; ///< Sprite name in ResourceManager.
24 bool m_modified; ///< True if modified since serialize().
25
26 public:
27 /// Animation constructor
29
30 /// Set associated Sprite to new one.
31 /// Note, Sprite is managed by ResourceManager.
32 /// Set Sprite index to 0 (first frame).
33 void setSprite(Sprite *p_new_sprite);
34
35 /// Return pointer to associated Sprite.
36 const Sprite *getSprite() const;
37
38 /// Set Sprite name (in ResourceManager).
39 void setName(std::string new_name);
40
41 /// Get Sprite name (in ResourceManager).
42 std::string getName() const;
43
44 /// Set index of current Sprite frame to be displayed.
45 void setIndex(int new_index);
46
47 /// Get index of current Sprite frame to be displayed.
48 int getIndex() const;
49
50 /// Set animation slowdown count (-1 means stop animation).
51 void setSlowdownCount(int new_slowdown_count);
52
53 /// Set animation slowdown count (-1 means stop animation).
54 int getSlowdownCount() const;
55
56 /// Get bounding box of associated Sprite.
57 Box getBox() const;
58
59 /// Serialize attributes to stream.
60 /// Return 0 if ok, else -1.
61 int serialize(std::stringstream *p_ss) const;
62
63 /// Deserialize attributes from stream.
64 /// Return 0 if ok, else -1.
65 int deserialize(std::stringstream *p_ss);
66
67 /// Return true if any attributes modified since last serialize.
68 bool isModified() const;
69
70 /// Draw single frame centered at position (x,y).
71 /// Drawing accounts for slowdown, and advances Sprite frame.
72 /// Return 0 if ok, else -1.
73 int draw(Vector position);
74
75 /// Compare two Animations.
76 bool operator==(const Animation &a);
77 bool operator!=(const Animation &a);
78
79 /// Return attributes as string.
80 std::string toString() const;
81};
82
83} // end of namespace df
84#endif // __ANIMATION_H__
Definition: Animation.h:17
Animation()
Animation constructor.
void setSlowdownCount(int new_slowdown_count)
Set animation slowdown count (-1 means stop animation).
int m_index
Current index frame for Sprite.
Definition: Animation.h:21
std::string toString() const
Return attributes as string.
Box getBox() const
Get bounding box of associated Sprite.
int getIndex() const
Get index of current Sprite frame to be displayed.
void setIndex(int new_index)
Set index of current Sprite frame to be displayed.
Sprite * m_p_sprite
Sprite associated with Animation.
Definition: Animation.h:20
int draw(Vector position)
Draw single frame centered at position (x,y).
int serialize(std::stringstream *p_ss) const
Serialize attributes to stream.
void setSprite(Sprite *p_new_sprite)
Set associated Sprite to new one.
int getSlowdownCount() const
Set animation slowdown count (-1 means stop animation).
const Sprite * getSprite() const
Return pointer to associated Sprite.
void setName(std::string new_name)
Set Sprite name (in ResourceManager).
std::string getName() const
Get Sprite name (in ResourceManager).
int m_slowdown_count
Slowdown counter (-1 means stop).
Definition: Animation.h:22
int deserialize(std::stringstream *p_ss)
Deserialize attributes from stream.
bool isModified() const
Return true if any attributes modified since last serialize.
bool operator==(const Animation &a)
Compare two Animations.
bool m_modified
True if modified since serialize().
Definition: Animation.h:24
std::string m_name
Sprite name in ResourceManager.
Definition: Animation.h:23
Definition: Box.h:16
Definition: Sprite.h:17
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15