Dragonfly 4.19
A text-based game engine
Sprite.h
1///
2/// The sprite
3///
4
5#ifndef __SPRITE_H__
6#define __SPRITE_H__
7
8// System includes.
9#include <string>
10
11// Engine includes.
12#include "Color.h"
13#include "Frame.h"
14
15namespace df {
16
17class Sprite {
18
19 private:
20 int m_width; ///< Sprite width.
21 int m_height; ///< Sprite height.
22 int m_max_frame_count; ///< Maximum number of frames sprite can have.
23 int m_frame_count; ///< Actual number of frames sprite has.
24 Color m_color; ///< Optional color for entire sprite.
25 int m_slowdown; ///< Animation slowdown (1 = no slowdown, 0 = stop).
26 char m_transparency; ///< Sprite transparent character (0 if none).
27 Frame *m_frame; ///< Array of frames.
28 std::string m_label; ///< Text label to identify sprite.
29 Sprite(); ///< Sprite always has one arg, the frame count.
30
31 public:
32 /// Delete sprite, removing any allocated frames.
34
35 /// Create sprite with indicated maximum number of frames.
36 Sprite(int max_frames);
37
38 /// Set width of sprite.
39 void setWidth(int new_width);
40
41 /// Get width of sprite.
42 int getWidth() const;
43
44 /// Set height of sprite.
45 void setHeight(int new_height);
46
47 /// Get height of sprite.
48 int getHeight() const;
49
50 /// Set sprite color.
51 void setColor(Color new_color);
52
53 /// Get sprite color.
54 Color getColor() const;
55
56 /// Get total count of frames in sprite.
57 int getFrameCount() const;
58
59 /// Add frame to sprite.
60 /// Return -1 if frame array full, else 0.
61 int addFrame(Frame new_frame);
62
63 /// Get next sprite frame indicated by number.
64 /// Return empty frame if out of range [0, m_frame_count-1].
65 Frame getFrame(int frame_number) const;
66
67 /// Set label associated with sprite.
68 void setLabel(std::string new_label);
69
70 /// Get label associated with sprite.
71 std::string getLabel() const;
72
73 /// Set animation slowdown value.
74 /// Value in multiples of GameManager frame time.
75 void setSlowdown(int new_sprite_slowdown);
76
77 // Get animation slowdown value.
78 // Value in multiples of GameManager frame time.
79 int getSlowdown() const;
80
81 /// Set Sprite transparency character (0 means none).
82 void setTransparency(char new_transparency);
83
84 /// Get Sprite transparency character (0 means none).
85 char getTransparency() const;
86
87 /// Draw indicated frame centered at position (x,y).
88 /// Don't draw transparent characters (0 means none).
89 /// Return 0 if ok, else -1.
90 /// Note: top-left coordinate is (0,0).
91 int draw(int frame_number, Vector position, char transparency) const;
92};
93
94} // end of namespace df
95#endif // __SPRITE_H__
Definition: Frame.h:17
Definition: Sprite.h:17
int m_slowdown
Animation slowdown (1 = no slowdown, 0 = stop).
Definition: Sprite.h:25
Sprite()
Sprite always has one arg, the frame count.
void setWidth(int new_width)
Set width of sprite.
Frame * m_frame
Array of frames.
Definition: Sprite.h:27
std::string m_label
Text label to identify sprite.
Definition: Sprite.h:28
int getFrameCount() const
Get total count of frames in sprite.
int m_width
Sprite width.
Definition: Sprite.h:20
void setLabel(std::string new_label)
Set label associated with sprite.
Color m_color
Optional color for entire sprite.
Definition: Sprite.h:24
void setSlowdown(int new_sprite_slowdown)
Set animation slowdown value.
char getTransparency() const
Get Sprite transparency character (0 means none).
int m_max_frame_count
Maximum number of frames sprite can have.
Definition: Sprite.h:22
void setColor(Color new_color)
Set sprite color.
void setHeight(int new_height)
Set height of sprite.
std::string getLabel() const
Get label associated with sprite.
int getHeight() const
Get height of sprite.
int draw(int frame_number, Vector position, char transparency) const
Draw indicated frame centered at position (x,y).
int m_height
Sprite height.
Definition: Sprite.h:21
~Sprite()
Delete sprite, removing any allocated frames.
char m_transparency
Sprite transparent character (0 if none).
Definition: Sprite.h:26
int getWidth() const
Get width of sprite.
Color getColor() const
Get sprite color.
Sprite(int max_frames)
Create sprite with indicated maximum number of frames.
void setTransparency(char new_transparency)
Set Sprite transparency character (0 means none).
Frame getFrame(int frame_number) const
Get next sprite frame indicated by number.
int addFrame(Frame new_frame)
Add frame to sprite.
int m_frame_count
Actual number of frames sprite has.
Definition: Sprite.h:23
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15
Color
Colors Dragonfly recognizes.
Definition: Color.h:11