Dragonfly 4.20
A text-based game engine
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
df::Object Class Reference
Inheritance diagram for df::Object:
Inheritance graph

Public Member Functions

 Object ()
 
virtual ~Object ()
 
void setId (int new_id)
 
int getId () const
 
virtual void setType (std::string new_type)
 
std::string getType () const
 
virtual int setPosition (Vector new_position)
 
Vector getPosition () const
 
virtual int eventHandler (const Event *p_event)
 
bool isSolid () const
 
virtual int setSolidness (Solidness new_solid)
 
Solidness getSolidness () const
 
void setNoSoft (bool new_no_soft=true)
 
bool getNoSoft () const
 
virtual void setAvoidCollisions (bool new_avoid_collisions=true)
 
bool getAvoidCollisions () const
 
virtual int setAltitude (int new_altitude)
 
int getAltitude () const
 
void setSpeed (float speed)
 
float getSpeed () const
 
virtual void setDirection (Vector new_direction)
 
Vector getDirection () const
 
virtual void setVelocity (Vector velocity)
 
Vector getVelocity () const
 
virtual 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 new_position)
 
void doPathFollowing ()
 
int setVisible (bool new_visible=true)
 
virtual bool isVisible () const
 
virtual int setActive (bool new_active=true)
 
bool isActive () const
 
virtual void setBox (Box new_box)
 
Box getBox () const
 
int registerInterest (std::string event_type)
 
int unregisterInterest (std::string event_type)
 
int getEventCount () const
 
virtual int setSprite (std::string sprite_label)
 
virtual void setAnimation (Animation new_animation, bool set_box=true)
 
Animation getAnimation () const
 
virtual int draw ()
 
virtual int serialize (std::stringstream *p_ss, unsigned int attr=0)
 
virtual int deserialize (std::stringstream *p_ss, unsigned int *p_a=NULL)
 
bool isModified (enum ObjectAttribute attribute) const
 
bool isModified () const
 
virtual void setModified (unsigned int new_modified)
 
virtual unsigned int getModified () const
 
virtual void setShape (Shape new_shape)
 
Shape getShape () const
 
virtual void setFollowPath (bool new_follow_path=true)
 
bool getFollowPath () const
 
void setPath (Path new_path)
 
Path getPath () const
 
PathFindgetPathFind ()
 
std::string toString () const
 
bool operator== (const Object &o)
 
bool operator!= (const Object &o)
 

Static Public Attributes

static int max_id
 

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
 
int m_altitude
 
Solidness m_solidness
 
Animation m_animation
 
bool m_no_soft
 
int m_event_count
 
std::string m_event_name [MAX_OBJ_EVENTS]
 
unsigned int m_modified
 
Shape m_shape
 
PathFindm_p_path_find
 
Path m_path
 
bool m_follow_path
 
bool m_avoid_collisions
 

Constructor & Destructor Documentation

◆ Object()

df::Object::Object ( )

Construct Object.

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

◆ ~Object()

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

Destroy Object.

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

Member Function Documentation

◆ accelerate()

void df::Object::accelerate ( )

Add acceleration to Object velocity.

(Typically done once per step by World Manager).

◆ deserialize()

virtual int df::Object::deserialize ( std::stringstream *  p_ss,
unsigned int *  p_a = NULL 
)
virtual

Deserialize stream to attributes and apply.

p_ss - incoming stream to deserialize. p_a - outgoing bitmask of attributes modified (NULL means no outgoing). Return 0 if ok, else -1.

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

◆ doPathFollowing()

void df::Object::doPathFollowing ( )

If following a path, update path progress.

◆ draw()

virtual int df::Object::draw ( )
virtual

Draw Object: Animation and/or Shape.

Return 0 if ok, else -1.

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

◆ eventHandler()

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::Fader, df::Button, df::Firework, df::Fraps, df::NetworkNode, df::Particle, df::Pause, df::Precipitation, df::Splash, df::SplashDragonfly, df::TextEntry, and df::ViewObject.

◆ getAcceleration()

Vector df::Object::getAcceleration ( ) const

Get acceleration of Object.

◆ getAltitude()

int df::Object::getAltitude ( ) const

Return altitude of Object.

◆ getAnimation()

Animation df::Object::getAnimation ( ) const

Get Animation for this Object.

◆ getAvoidCollisions()

bool df::Object::getAvoidCollisions ( ) const

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

◆ getBox()

Box df::Object::getBox ( ) const

Get bounding box of Object.

◆ getDirection()

Vector df::Object::getDirection ( ) const

Get direction of Object.

◆ getEventCount()

int df::Object::getEventCount ( ) const

Get registered interest event count.

◆ getFollowPath()

bool df::Object::getFollowPath ( ) const

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

◆ getId()

int df::Object::getId ( ) const

Get Object id.

◆ getModified()

virtual unsigned int df::Object::getModified ( ) const
virtual

Return modified attribute mask.

◆ getNoSoft()

bool df::Object::getNoSoft ( ) const

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

◆ getPath()

Path df::Object::getPath ( ) const

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

◆ getPathFind()

PathFind * df::Object::getPathFind ( )

Get object doing pathfinding.

◆ getPosition()

Vector df::Object::getPosition ( ) const

Get position of Object.

◆ getShape()

Shape df::Object::getShape ( ) const

Get drawing shape.

◆ getSolidness()

Solidness df::Object::getSolidness ( ) const

Return solidness of Object.

◆ getSpeed()

float df::Object::getSpeed ( ) const

Get speed of Object.

◆ getType()

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

Get type identifier of Object.

◆ getVelocity()

Vector df::Object::getVelocity ( ) const

Get velocity of Object based on direction and speed.

◆ isActive()

bool df::Object::isActive ( ) const

Return activeness of Object.

Objects not active are not acted upon by engine.

◆ isModified() [1/2]

bool df::Object::isModified ( ) const

Return true if any attribute modified since last serialize.

◆ isModified() [2/2]

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

Return true if attribute modified since last serialize.

◆ isSolid()

bool df::Object::isSolid ( ) const

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

◆ isVisible()

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

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

◆ moveTo()

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

Set direction of Object towards position.

(Called when pathfinding).

◆ operator==()

bool df::Object::operator== ( const Object o)

Compare two Objects.

◆ pathTo() [1/2]

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.

◆ pathTo() [2/2]

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

Navigate Object from current position to target position using pathfinding.

Turns on avoid collisions.

◆ predictPosition()

Vector df::Object::predictPosition ( )

Predict Object position based on speed and direction.

Return predicted position.

◆ registerInterest()

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.

◆ serialize()

virtual int df::Object::serialize ( std::stringstream *  p_ss,
unsigned int  attr = 0 
)
virtual

Serialize attributes to stream.

Can specify individual attribute(s) to force (modified or not). Default is only modified attributes. Clears modified bits for attributes serialized. Return 0 if ok, else -1.

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

◆ setAcceleration()

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

Set acceleration of Object.

◆ setActive()

virtual int df::Object::setActive ( bool  new_active = true)
virtual

Set activeness of Object.

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

◆ setAltitude()

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

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

Return 0 if ok, else -1.

◆ setAnimation()

virtual void df::Object::setAnimation ( Animation  new_animation,
bool  set_box = true 
)
virtual

Set Animation for this Object to new one.

If set_box is true, set bounding box to size of associated Sprite.

◆ setAvoidCollisions()

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

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

◆ setBox()

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

Set bounding box of Object.

◆ setDirection()

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

Set direction of Object.

◆ setFollowPath()

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

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

If path defined, start moving to first node.

◆ setId()

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

Set Object id.

◆ setModified()

virtual void df::Object::setModified ( unsigned int  new_modified)
virtual

Set modified attribute mask.

◆ setNoSoft()

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

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

◆ setPath()

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

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

◆ setPosition()

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

Set position of Object.

Return 0 if ok, else -1.

Reimplemented in df::ViewObject.

◆ setShape()

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

Set drawing shape.

◆ setSolidness()

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

Set solidness of Object, with checks for consistency.


Return 0 if ok, else -1.

◆ setSpeed()

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

Set speed of Object.

◆ setSprite()

virtual int df::Object::setSprite ( std::string  sprite_label)
virtual

Set Sprite for this Object to animate.

Return 0 if ok, else -1.

◆ setType()

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

Set type identifier of Object.

◆ setVelocity()

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

Set direction and speed of Object.

◆ setVisible()

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

Set visibility of Object.

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

◆ toString()

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

Return base attributes as string.

◆ unregisterInterest()

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

Unregister for interest in event.


Return 0 if ok, else -1.

Member Data Documentation

◆ m_acceleration

Vector df::Object::m_acceleration
private

Acceleration vector.

◆ m_altitude

int df::Object::m_altitude
private

0 to MAX_ALTITUDE (higher drawn on top).

◆ m_animation

Animation df::Object::m_animation
private

Animation associated with Object.

◆ m_avoid_collisions

bool df::Object::m_avoid_collisions
private

True if should avoid collisions with HARD.

◆ m_box

Box df::Object::m_box
private

Box for sprite boundary & collisions.

◆ m_direction

Vector df::Object::m_direction
private

Direction vector.

◆ m_event_count

int df::Object::m_event_count
private

Number of events of interest.

◆ m_event_name

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

Names of events interested in.

◆ m_follow_path

bool df::Object::m_follow_path
private

True if following path.

◆ m_id

int df::Object::m_id
private

Unique game engine defined identifier.

◆ m_is_active

bool df::Object::m_is_active
private

If false, Object not acted upon.

◆ m_is_visible

bool df::Object::m_is_visible
private

If true, Object gets drawn.

◆ m_modified

unsigned int df::Object::m_modified
private

Mod. attributes mask since last serialize().

◆ m_no_soft

bool df::Object::m_no_soft
private

True if won't move on SOFT Objects.

◆ m_p_path_find

PathFind* df::Object::m_p_path_find
private

Object performing pathfinding.

◆ m_path

Path df::Object::m_path
private

If following path, holds path information.

◆ m_position

Vector df::Object::m_position
private

Position in game world.

◆ m_shape

Shape df::Object::m_shape
private

Basic geometric shape to draw.

◆ m_solidness

Solidness df::Object::m_solidness
private

Solidness state of Object.

◆ m_speed

float df::Object::m_speed
private

Object speed in direction.

◆ m_type

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

Game programmer defined type.

◆ max_id

int df::Object::max_id
static

Monotonically increasing identifier.