Dragonfly 4.20
A text-based game engine
Public Member Functions | Private Member Functions | Private Attributes | List of all members
df::Sprite Class Reference

Public Member Functions

 ~Sprite ()
 
 Sprite (int max_frames)
 
void setWidth (int new_width)
 
int getWidth () const
 
void setHeight (int new_height)
 
int getHeight () const
 
void setColor (Color new_color)
 
Color getColor () const
 
int getFrameCount () const
 
int addFrame (Frame new_frame)
 
Frame getFrame (int frame_number) const
 
void setLabel (std::string new_label)
 
std::string getLabel () const
 
void setSlowdown (int new_sprite_slowdown)
 
int getSlowdown () const
 
void setTransparency (char new_transparency)
 
char getTransparency () const
 
int draw (int frame_number, Vector position, char transparency) const
 
std::string toString () const
 

Private Member Functions

 Sprite ()
 

Private Attributes

int m_width
 
int m_height
 
int m_max_frame_count
 
int m_frame_count
 
Color m_color
 
int m_slowdown
 
char m_transparency
 
Framem_frame
 
std::string m_label
 

Constructor & Destructor Documentation

◆ Sprite() [1/2]

df::Sprite::Sprite ( )
private

Sprite always has one arg, the frame count.

◆ ~Sprite()

df::Sprite::~Sprite ( )

Delete sprite, removing any allocated frames.

◆ Sprite() [2/2]

df::Sprite::Sprite ( int  max_frames)

Create sprite with indicated maximum number of frames.

Member Function Documentation

◆ addFrame()

int df::Sprite::addFrame ( Frame  new_frame)

Add frame to sprite.

Return -1 if frame array full, else 0.

◆ draw()

int df::Sprite::draw ( int  frame_number,
Vector  position,
char  transparency 
) const

Draw indicated frame centered at position (x,y).

Don't draw transparent characters (0 means none). Return 0 if ok, else -1. Note: top-left coordinate is (0,0).

◆ getColor()

Color df::Sprite::getColor ( ) const

Get sprite color.

◆ getFrame()

Frame df::Sprite::getFrame ( int  frame_number) const

Get next sprite frame indicated by number.

Return empty frame if out of range [0, m_frame_count-1].

◆ getFrameCount()

int df::Sprite::getFrameCount ( ) const

Get total count of frames in sprite.

◆ getHeight()

int df::Sprite::getHeight ( ) const

Get height of sprite.

◆ getLabel()

std::string df::Sprite::getLabel ( ) const

Get label associated with sprite.

◆ getTransparency()

char df::Sprite::getTransparency ( ) const

Get Sprite transparency character (0 means none).

◆ getWidth()

int df::Sprite::getWidth ( ) const

Get width of sprite.

◆ setColor()

void df::Sprite::setColor ( Color  new_color)

Set sprite color.

◆ setHeight()

void df::Sprite::setHeight ( int  new_height)

Set height of sprite.

◆ setLabel()

void df::Sprite::setLabel ( std::string  new_label)

Set label associated with sprite.

◆ setSlowdown()

void df::Sprite::setSlowdown ( int  new_sprite_slowdown)

Set animation slowdown value.

Value in multiples of GameManager frame time.

◆ setTransparency()

void df::Sprite::setTransparency ( char  new_transparency)

Set Sprite transparency character (0 means none).

◆ setWidth()

void df::Sprite::setWidth ( int  new_width)

Set width of sprite.

◆ toString()

std::string df::Sprite::toString ( ) const

Return attributes as string.

Member Data Documentation

◆ m_color

Color df::Sprite::m_color
private

Optional color for entire sprite.

◆ m_frame

Frame* df::Sprite::m_frame
private

Array of frames.

◆ m_frame_count

int df::Sprite::m_frame_count
private

Actual number of frames sprite has.

◆ m_height

int df::Sprite::m_height
private

Sprite height.

◆ m_label

std::string df::Sprite::m_label
private

Text label to identify sprite.

◆ m_max_frame_count

int df::Sprite::m_max_frame_count
private

Maximum number of frames sprite can have.

◆ m_slowdown

int df::Sprite::m_slowdown
private

Animation slowdown (1 = no slowdown, 0 = stop).

◆ m_transparency

char df::Sprite::m_transparency
private

Sprite transparent character (0 if none).

◆ m_width

int df::Sprite::m_width
private

Sprite width.