Dragonfly 4.19
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
 
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
 
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 new_position)
 
void doPathFollowing ()
 
int setVisible (bool new_visible=true)
 
bool isVisible () const
 
int setActive (bool new_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)
 
int setSprite (std::string sprite_label)
 
void setAnimation (Animation new_animation, bool set_box=true)
 
Animation getAnimation () const
 
virtual int draw ()
 
virtual std::string serialize (std::string attr="")
 
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 ()
 
std::string toString () const
 

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]
 
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

◆ 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::string  s)
virtual

Deserialize string to become attributes and apply.

Return 0 if no errors, else -1.

Reimplemented in df::Button, df::Particle, 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::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::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.

◆ 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.

◆ 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]

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

Return true if any attribute modified since last serialize.

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

◆ isModified() [2/2]

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

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()

bool df::Object::isVisible ( ) const

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).

◆ 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 std::string df::Object::serialize ( std::string  attr = "")
virtual

Serialize attributes to string.

e.g., "id:4,pos-x:2.2,pos-y:0.9...". Default ("") is only attributes modified since last serialize(). Can specify specific attribute(s) to serialize (modified or not). separated by commas. If attr is "ALL" then serialize all attributes (modified or not). Clear m_modified[] array for attributes serialized.

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

◆ setAcceleration()

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

Set acceleration of Object.

◆ setActive()

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

Set activeness of Object.

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

◆ setAltitude()

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

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

Return 0 if ok, else -1.

◆ setAnimation()

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

Set Animation for this Object to new one.

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

◆ setAvoidCollisions()

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

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

◆ setBox()

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

Set bounding box of Object.

◆ setDirection()

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

Set direction of Object.

◆ setFollowPath()

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.

◆ setId()

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

Set Object id.

◆ 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()

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

Set drawing shape.

◆ setSolidness()

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

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()

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

Set Sprite for this Object to animate.

Return 0 if ok, else -1.

◆ setType()

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

Set type identifier of Object.

◆ setVelocity()

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

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

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

Mod. attrib. 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.