Dragonfly  4.3
A text-based game engine
Public Member Functions | Private Attributes | List of all members
df::Object Class Reference
Inheritance diagram for df::Object:
Inheritance graph
[legend]
Collaboration diagram for df::Object:
Collaboration graph
[legend]

Public Member Functions

 Object ()
 
virtual ~Object ()
 
void setId (int new_id)
 
int getId () const
 
void setType (std::string new_type)
 
std::string getType () const
 
virtual void setPosition (Vector new_position)
 
Vector getPosition () const
 
virtual int eventHandler (const Event *p_event)
 
bool isSolid () const
 
int setSolidness (Solidness new_solid)
 
Solidness getSolidness () const
 
void setNoSoft (bool new_no_soft=true)
 
bool getNoSoft () const
 
void setAvoidCollisions (bool new_avoid_collisions=true)
 
bool getAvoidCollisions () const
 
int setAltitude (int new_altitude)
 
int getAltitude () const
 
void setSpeed (float speed)
 
float getSpeed () const
 
void setDirection (Vector new_direction)
 
Vector getDirection () const
 
void setVelocity (Vector velocity)
 
Vector getVelocity () const
 
void setAcceleration (Vector new_acceleration)
 
Vector getAcceleration () const
 
void accelerate ()
 
Vector predictPosition ()
 
void pathTo (Vector position)
 
void pathTo (Object *p_o_target)
 
void moveTo (Vector position)
 
void doPathFollowing ()
 
int setVisible (bool visible=true)
 
bool isVisible () const
 
int setActive (bool active=true)
 
bool isActive () const
 
void setBox (Box new_box)
 
Box getBox () const
 
int registerInterest (std::string event_type)
 
int unregisterInterest (std::string event_type)
 
virtual void draw ()
 
void setSpriteName (std::string new_name)
 
std::string getSpriteName () const
 
void setSprite (Sprite *p_new_sprite, bool set_box=true)
 
SpritegetSprite () const
 
void setCentered (bool centered=true)
 
bool isCentered () const
 
void setTransparency (char transparent=' ')
 
char getTransparency () const
 
void setSpriteIndex (int new_sprite_index)
 
int getSpriteIndex () const
 
void setSpriteSlowdown (int new_sprite_slowdown)
 
int getSpriteSlowdown () const
 
void setSpriteSlowdownCount (int new_sprite_slowdown_count)
 
int getSpriteSlowdownCount () const
 
virtual std::string serialize (bool all=false)
 
virtual int deserialize (std::string s)
 
virtual bool isModified (enum ObjectAttribute attribute) const
 
virtual bool isModified () const
 
void setShape (Shape new_shape)
 
Shape getShape () const
 
void setFollowPath (bool new_follow_path=true)
 
bool getFollowPath () const
 
void setPath (Path new_path)
 
Path getPath () const
 
PathFindgetPathFind ()
 

Private Attributes

int m_id
 
std::string m_type
 
bool m_is_active
 
bool m_is_visible
 
Box m_box
 
Vector m_position
 
Vector m_direction
 
float m_speed
 
Vector m_acceleration
 
std::string sprite_name
 
Spritem_p_sprite
 
bool m_sprite_center
 
char m_sprite_transparency
 
int m_sprite_index
 
int m_sprite_slowdown
 
int m_sprite_slowdown_count
 
int m_altitude
 
Solidness m_solidness
 
bool m_no_soft
 
int m_event_count
 
std::string m_event_name [MAX_OBJ_EVENTS]
 
bool m_modified [ATTR_COUNT]
 
Shape m_shape
 
PathFindm_p_path_find
 
Path m_path
 
bool m_follow_path
 
bool m_avoid_collisions
 

Constructor & Destructor Documentation

df::Object::Object ( )

Construct Object.

Set default parameters and add to game world (WorldManager).

virtual df::Object::~Object ( )
virtual

Destroy Object.

Unregister for any interested events. Remove from game world (WorldManager).

Member Function Documentation

void df::Object::accelerate ( )

Add acceleration to Object velocity.

(Typically done once per step by World Manager).

virtual int df::Object::deserialize ( std::string  s)
virtual

Deserialize string to become attributes.

Return 0 if no errors, else -1.

Reimplemented in df::ViewObject, df::TextEntry, and df::Button.

void df::Object::doPathFollowing ( )

If following a path, update path progress.

virtual void df::Object::draw ( )
virtual

Draw single Sprite Frame.

Drawing accounts for centering & slowdown, and advances Sprite Frame.

Reimplemented in df::TextEntry, and df::ViewObject.

virtual int df::Object::eventHandler ( const Event p_event)
virtual

Handle event (default only handles pathfinding).

Return 0 if ignored, else 1.

Reimplemented in df::ViewObject, df::Particle, df::TextEntry, df::Fraps, df::Button, df::Precipitation, df::Firework, df::SplashDragonfly, df::Pause, and df::Splash.

Vector df::Object::getAcceleration ( ) const

Get acceleration of Object.

int df::Object::getAltitude ( ) const

Return altitude of Object.

bool df::Object::getAvoidCollisions ( ) const

Get "avoid collisions" (true - avoid collisions with HARD when moving).

Box df::Object::getBox ( ) const

Get bounding box of Object.

Vector df::Object::getDirection ( ) const

Get direction of Object.

bool df::Object::getFollowPath ( ) const

Returns true if following a path (note: is set in pathTo() method).

int df::Object::getId ( ) const

Get Object id.

bool df::Object::getNoSoft ( ) const

Get "no soft" setting of Object (true - cannot move onto SOFT Objects).

Path df::Object::getPath ( ) const

Get Path (note: is set in pathTo() method).

PathFind* df::Object::getPathFind ( )

Get object doing pathfinding.

Vector df::Object::getPosition ( ) const

Get position of Object.

Shape df::Object::getShape ( ) const

Get drawing shape.

Solidness df::Object::getSolidness ( ) const

Return solidness of Object.

float df::Object::getSpeed ( ) const

Get speed of Object.

Sprite* df::Object::getSprite ( ) const

Return pointer to Sprite associated with this Object.

int df::Object::getSpriteIndex ( ) const

Return index of current Sprite frame to be displayed.

std::string df::Object::getSpriteName ( ) const

Get Sprite name (in ResourceManager) for Object.

char df::Object::getTransparency ( ) const

Get Sprite transparency character (0 means none).

std::string df::Object::getType ( ) const

Get type identifier of Object.

Vector df::Object::getVelocity ( ) const

Get velocity of Object based on direction and speed.

bool df::Object::isActive ( ) const

Return activeness of Object.

Objects not active are not acted upon by engine.

bool df::Object::isCentered ( ) const

Indicates if Sprite is centered at Object position.

virtual bool df::Object::isModified ( enum ObjectAttribute  attribute) const
virtual

Return true if attribute modified since last serialize.

virtual bool df::Object::isModified ( ) const
virtual

Return true if any attribute modified since last serialize.

Reimplemented in df::ViewObject, df::TextEntry, and df::Button.

bool df::Object::isSolid ( ) const

Return True if Object is HARD or SOFT, else false.

bool df::Object::isVisible ( ) const

Return visibility of Object. Objects not visible are not drawn.

void df::Object::moveTo ( Vector  position)

Set direction of Object towards position.

(Called when pathfinding).

void df::Object::pathTo ( Vector  position)

Navigate Object from current position to target position using pathfinding.

Turns on avoid collisions.

void df::Object::pathTo ( Object p_o_target)

Navigate Object from current position to current position of target Object using pathfinding.

Turns on avoid collisions.

Vector df::Object::predictPosition ( )

Predict Object position based on speed and direction.

Return predicted position.

int df::Object::registerInterest ( std::string  event_type)

Register for interest in event.

Keeps track of manager and event. Return 0 if ok, else -1.

virtual std::string df::Object::serialize ( bool  all = false)
virtual

Serialize attributes to single string.

e.g., "id:110,is_active:true, ... Only modified attributes are serialized (unless all is true). Clear modified[] array.

Reimplemented in df::ViewObject, df::TextEntry, and df::Button.

void df::Object::setAcceleration ( Vector  new_acceleration)

Set acceleration of Object.

int df::Object::setActive ( bool  active = true)

Set activeness of Object.

Objects not active are not acted upon by engine. Return 0 if ok, else -1.

int df::Object::setAltitude ( int  new_altitude)

Set altitude of Object, with checks for range [0, MAX_ALTITUDE].

Return 0 if ok, else -1.

void df::Object::setAvoidCollisions ( bool  new_avoid_collisions = true)

Set "avoid collisions" (true - avoid collisions with HARD when moving).

void df::Object::setBox ( Box  new_box)

Set bounding box of Object.

void df::Object::setCentered ( bool  centered = true)

Set Sprite to be centered at Object position.

Adjust bounding box of Sprite.

void df::Object::setDirection ( Vector  new_direction)

Set direction of Object.

void df::Object::setFollowPath ( bool  new_follow_path = true)

Set follow_path (note: is also set in pathTo() method).

If path defined, start moving to first node.

void df::Object::setId ( int  new_id)

Set Object id.

void df::Object::setNoSoft ( bool  new_no_soft = true)

Set "no soft" setting of Object (true - cannot move onto SOFT Objects).

void df::Object::setPath ( Path  new_path)

Set Path (note: is also set in pathTo() method).

virtual void df::Object::setPosition ( Vector  new_position)
virtual

Set position of Object.

Reimplemented in df::ViewObject.

void df::Object::setShape ( Shape  new_shape)

Set drawing shape.

int df::Object::setSolidness ( Solidness  new_solid)

Set solidness of Object, with checks for consistency.

Return 0 if ok, else -1.

void df::Object::setSpeed ( float  speed)

Set speed of Object.

void df::Object::setSprite ( Sprite p_new_sprite,
bool  set_box = true 
)

Set Object Sprite to new one.

If set_box is true, set bounding box to size of Sprite. Set sprite index to 0 (first frame).

void df::Object::setSpriteIndex ( int  new_sprite_index)

Set index of current Sprite frame to be displayed.

void df::Object::setSpriteName ( std::string  new_name)

Set Sprite name (in ResourceManager) for Object.

void df::Object::setSpriteSlowdown ( int  new_sprite_slowdown)

Slows down sprite animations.

Slowdown value in multiples of GameManager frame time.

void df::Object::setTransparency ( char  transparent = ' ')

Set Sprite transparency character (0 means none).

void df::Object::setType ( std::string  new_type)

Set type identifier of Object.

void df::Object::setVelocity ( Vector  velocity)

Set direction and speed of Object.

int df::Object::setVisible ( bool  visible = true)

Set visibility of Object.

Objects not visible are not drawn. Return 0 if ok, else -1.

int df::Object::unregisterInterest ( std::string  event_type)

Unregister for interest in event.

Return 0 if ok, else -1.

Member Data Documentation

Vector df::Object::m_acceleration
private

Acceleration vector.

int df::Object::m_altitude
private

0 to MAX_ALTITUDE (higher drawn on top).

bool df::Object::m_avoid_collisions
private

True if should avoid collisions with HARD.

Box df::Object::m_box
private

Box for sprite boundary & collisions.

Vector df::Object::m_direction
private

Direction vector.

int df::Object::m_event_count
private

Number of events of interest.

std::string df::Object::m_event_name[MAX_OBJ_EVENTS]
private

Names of events interested in.

bool df::Object::m_follow_path
private

True if following path.

int df::Object::m_id
private

Unique game engine defined identifier.

bool df::Object::m_is_active
private

If false, Object not acted upon.

bool df::Object::m_is_visible
private

If true, Object gets drawn.

bool df::Object::m_modified[ATTR_COUNT]
private

Mod. attrib. since last serialize().

bool df::Object::m_no_soft
private

True if won't move on SOFT Objects.

PathFind* df::Object::m_p_path_find
private

Object performing pathfinding.

Sprite* df::Object::m_p_sprite
private

Sprite associated with Object.

Path df::Object::m_path
private

If following path, holds path information.

Vector df::Object::m_position
private

Position in game world.

Shape df::Object::m_shape
private

Basic geometric shape to draw.

Solidness df::Object::m_solidness
private

Solidness state of Object.

float df::Object::m_speed
private

Object speed in direction.

bool df::Object::m_sprite_center
private

True if sprite centered on position.

int df::Object::m_sprite_index
private

Current index frame for sprite.

int df::Object::m_sprite_slowdown
private

Slowdown rate (1 = no slowdown, 0 = stop).

int df::Object::m_sprite_slowdown_count
private

Slowdown counter.

char df::Object::m_sprite_transparency
private

Sprite transparent character (0 if none).

std::string df::Object::m_type
private

Game-programmer defined identification.

std::string df::Object::sprite_name
private