The Game Engine  1
WorldObject Class Referenceabstract

Base class for Any object that will ever be drawn to the screen. More...

#include <WorldObject.h>

+ Inheritance diagram for WorldObject:
+ Collaboration diagram for WorldObject:

Public Types

enum  WorldObjectType {
  SPRITE, BACKGROUND, MENU, TEXT,
  PARTICLESYSTEM
}
 This is to be used for Type checking so as to make no need for dynamic_cast and it's inefficiency. More...
 

Public Member Functions

 WorldObject (std::string name, Point2D pos=Point2D(), int z=0)
 
virtual void draw ()=0
 Draws the Object. More...
 
virtual void drawCollisions ()
 Draws CollisionObject data for the Object. More...
 
void drawCollisions (vector< CollisionObject * > &vec, const Point2D &pos)
 Draws CollisionObject data for the Object. More...
 
virtual void update ()
 Update to run each loop. More...
 
virtual void runBehavior ()
 Behavior that WorldObject follows. More...
 
void setPosition (double x, double y)
 Sets the WorldObject's x an y coordinate. More...
 
void setPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate. More...
 
void setBasePosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setBasePosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (double x, double y)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void setCenterPosition (Point2D pos)
 Sets the WorldObject's x an y coordinate relative to base pos. More...
 
void move (double dx=0.0, double dy=0.0)
 Move by given amount NOTE: This is an instantaneous movement by a given amount and does not correspond to physics which is set to do the updated amount per second. More...
 
virtual void move (Point2D direction)
 Moves the WorldObject relative to the current pos. More...
 
virtual void moveTowards (Point2D direction)
 Move towards a given coordinate (path finding) More...
 
Point2D getPosition ()
 Gets the WorldObject's position. More...
 
void setTransparency (float f)
 Sets the WorldObject's transparency. More...
 
float getTransparency ()
 Gets the WorldObject's transparency. More...
 
void setAngle (float a)
 Sets the WorldObject's angle in degrees. More...
 
float getAngle ()
 Gets the WorldObject's angle. More...
 
void setVelocity (Point2D vel)
 Sets the WorldObject's velocity as a vector (will set MaxVelocity if needed) More...
 
void setVelocity (double xVel, double yVel)
 Sets the WorldObject's velocity from coordinates (will set MaxVelocity if needed) More...
 
Point2D getVelocity ()
 Gets the WorldObject's Velocity. More...
 
void setMaxVelocity (Point2D vel)
 Sets the WorldObject's MaxVelocity (magnitude) from (x,y) and transforms into a magnitude. More...
 
void setMaxVelocity (double vel, Point2D dir)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
void setMaxSpeed (double vel)
 Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified. More...
 
Point2D getMaxVelocity ()
 Gets the WorldObject's Max Velocity. More...
 
double getMaxSpeed ()
 Gets the WorldObject's Max Speed. More...
 
double getMaxSpeedSquared ()
 Gets the WorldObject's Max Speed Squared (cheaper operation). More...
 
void setAcceleration (Point2D accel)
 Sets the WorldObject's Acceleration in (x,y) coords. More...
 
Point2D getAcceleration ()
 Gets the WorldObject's Acceleration. More...
 
void setZOrder (int i)
 
int getZOrder ()
 
std::string getName ()
 returns the WorldObject's name More...
 
bool operator< (WorldObject &rhs)
 Sort worldObjects. More...
 
virtual Point2D getBasePos ()=0
 Obtain Base Pos for drawing. More...
 
virtual Point2D getCenterPos ()=0
 Obtain Center Pos for Collisions. More...
 
virtual WorldObjectType getType ()=0
 This provides a simple interface to determine types of objects. More...
 

Protected Attributes

std::string mName
 WorldObject's name. More...
 
Point2D mPos
 The current (x,y) position. More...
 
Point2D mVelocity
 The current velocity vector. More...
 
Point2D mMaxVelocity
 The max velocity is the max possible velocity where lengthis the speed. More...
 
double mMaxSpeed
 The max Speed if MaxVelocity is 0 to store val. More...
 
Point2D mAcceleration
 The current acceleration vector. More...
 
bool mVisible
 Determine if Object should be visible. More...
 
float mTransparency
 Transparency! More...
 
float mAngle
 Angle of rotation. More...
 
float mScale
 Scale for the sprit. More...
 
int ZOrder
 Stacking order. Determines what draws on top. (subsorted by position) More...
 
long mLastUpdate
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
long mLastDraw
 Number that indicates when the Object has last updated. Overflows in about 24 days so no worries. More...
 
bool mUnused
 Determines whether or not this object's update function should run. More...
 
Behavior mBehavior
 Behavior to act each loop if !mUnused. More...
 

Detailed Description

Base class for Any object that will ever be drawn to the screen.

This class is tasked with the following:

  • Keeping Position
  • Defines basic physics (velocity, acceleration) (helper fn)
  • Handling visibility
  • Handling being 'active' in game (mUnused)
  • Defines Ordering Of WorldObjects

Definition at line 19 of file WorldObject.h.

Member Enumeration Documentation

This is to be used for Type checking so as to make no need for dynamic_cast and it's inefficiency.

Todo:
make sure to put all WorldObject children in here!
Enumerator
SPRITE 
BACKGROUND 
MENU 
TEXT 
PARTICLESYSTEM 

Definition at line 28 of file WorldObject.h.

Constructor & Destructor Documentation

WorldObject::WorldObject ( std::string  name,
Point2D  pos = Point2D(),
int  z = 0 
)

Definition at line 5 of file WorldObject.cpp.

+ Here is the call graph for this function:

Member Function Documentation

virtual void WorldObject::draw ( )
pure virtual

Draws the Object.

Implemented in ParticleSystem, Sprite, Text, Background, and Menu.

void WorldObject::drawCollisions ( )
virtual

Draws CollisionObject data for the Object.

Reimplemented in ParticleSystem, Background, Sprite, and Menu.

Definition at line 25 of file WorldObject.cpp.

+ Here is the caller graph for this function:

void WorldObject::drawCollisions ( vector< CollisionObject * > &  vec,
const Point2D pos 
)

Draws CollisionObject data for the Object.

Definition at line 48 of file WorldObject.cpp.

Point2D WorldObject::getAcceleration ( )
inline

Gets the WorldObject's Acceleration.

Definition at line 220 of file WorldObject.h.

float WorldObject::getAngle ( )
inline

Gets the WorldObject's angle.

Definition at line 136 of file WorldObject.h.

virtual Point2D WorldObject::getBasePos ( )
pure virtual

Obtain Base Pos for drawing.

Implemented in ParticleSystem, Sprite, Background, Text, and Menu.

+ Here is the caller graph for this function:

virtual Point2D WorldObject::getCenterPos ( )
pure virtual

Obtain Center Pos for Collisions.

Implemented in ParticleSystem, Sprite, Background, Text, and Menu.

+ Here is the caller graph for this function:

double WorldObject::getMaxSpeed ( )

Gets the WorldObject's Max Speed.

Definition at line 54 of file WorldObject.cpp.

+ Here is the call graph for this function:

double WorldObject::getMaxSpeedSquared ( )

Gets the WorldObject's Max Speed Squared (cheaper operation).

if mMaxspeed 0 then use the lengthsquared otherwise use the mMaxSpeed squared

Definition at line 58 of file WorldObject.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point2D WorldObject::getMaxVelocity ( )
inline

Gets the WorldObject's Max Velocity.

Definition at line 199 of file WorldObject.h.

std::string WorldObject::getName ( )
inline

returns the WorldObject's name

Definition at line 228 of file WorldObject.h.

Point2D WorldObject::getPosition ( )
inline

Gets the WorldObject's position.

Definition at line 114 of file WorldObject.h.

+ Here is the caller graph for this function:

float WorldObject::getTransparency ( )
inline

Gets the WorldObject's transparency.

Definition at line 125 of file WorldObject.h.

virtual WorldObjectType WorldObject::getType ( )
pure virtual

This provides a simple interface to determine types of objects.

Returns the name of the Class and Descendants i.e. Something inheriting from Sprite would look like Sprite:Thing

Implemented in ParticleSystem, Sprite, Background, Text, and Menu.

+ Here is the caller graph for this function:

Point2D WorldObject::getVelocity ( )
inline

Gets the WorldObject's Velocity.

Definition at line 165 of file WorldObject.h.

int WorldObject::getZOrder ( )
inline

Definition at line 223 of file WorldObject.h.

+ Here is the caller graph for this function:

void WorldObject::move ( double  dx = 0.0,
double  dy = 0.0 
)
inline

Move by given amount NOTE: This is an instantaneous movement by a given amount and does not correspond to physics which is set to do the updated amount per second.

Parameters
dxAmount to move x relative to current position
dyAmount to move y relative to current position

Definition at line 97 of file WorldObject.h.

+ Here is the caller graph for this function:

virtual void WorldObject::move ( Point2D  direction)
inlinevirtual

Moves the WorldObject relative to the current pos.

Parameters
directionDirection to move the WorldObject

Definition at line 103 of file WorldObject.h.

void WorldObject::moveTowards ( Point2D  direction)
virtual

Move towards a given coordinate (path finding)

Parameters
directionDirection to move the WorldObject towards
Todo:
Implement with AI
Todo:
have Point2D keep track of magnitude for useability later
Todo:
move velocity magnitude towards direction defaultly or pathfind

Definition at line 63 of file WorldObject.cpp.

bool WorldObject::operator< ( WorldObject rhs)
inline

Sort worldObjects.

Definition at line 233 of file WorldObject.h.

+ Here is the call graph for this function:

void WorldObject::runBehavior ( )
virtual

Behavior that WorldObject follows.

Reimplemented in ParticleSystem, and Sprite.

Definition at line 43 of file WorldObject.cpp.

+ Here is the caller graph for this function:

void WorldObject::setAcceleration ( Point2D  accel)
inline

Sets the WorldObject's Acceleration in (x,y) coords.

Parameters
accelAcceleration in (x,y) coords

Definition at line 215 of file WorldObject.h.

+ Here is the caller graph for this function:

void WorldObject::setAngle ( float  a)
inline

Sets the WorldObject's angle in degrees.

Parameters
aAngle in degrees

Definition at line 131 of file WorldObject.h.

void WorldObject::setBasePosition ( double  x,
double  y 
)
inline

Sets the WorldObject's x an y coordinate relative to base pos.

Definition at line 75 of file WorldObject.h.

+ Here is the call graph for this function:

void WorldObject::setBasePosition ( Point2D  pos)
inline

Sets the WorldObject's x an y coordinate relative to base pos.

Definition at line 80 of file WorldObject.h.

+ Here is the call graph for this function:

void WorldObject::setCenterPosition ( double  x,
double  y 
)
inline

Sets the WorldObject's x an y coordinate relative to base pos.

Definition at line 85 of file WorldObject.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WorldObject::setCenterPosition ( Point2D  pos)
inline

Sets the WorldObject's x an y coordinate relative to base pos.

Definition at line 90 of file WorldObject.h.

+ Here is the call graph for this function:

void WorldObject::setMaxSpeed ( double  vel)
inline

Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified.

Parameters
velMaxVelocity as magnitude

Definition at line 187 of file WorldObject.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WorldObject::setMaxVelocity ( Point2D  vel)
inline

Sets the WorldObject's MaxVelocity (magnitude) from (x,y) and transforms into a magnitude.

Parameters
velMaxVelocity in (x,y) coords

Definition at line 171 of file WorldObject.h.

+ Here is the caller graph for this function:

void WorldObject::setMaxVelocity ( double  vel,
Point2D  dir 
)
inline

Sets the WorldObject's MaxVelocity (magnitude) value in the direction specified.

Parameters
velMaxVelocity as magnitude
dirDirection of velocity

Definition at line 178 of file WorldObject.h.

+ Here is the call graph for this function:

void WorldObject::setPosition ( double  x,
double  y 
)
inline

Sets the WorldObject's x an y coordinate.

Definition at line 65 of file WorldObject.h.

+ Here is the caller graph for this function:

void WorldObject::setPosition ( Point2D  pos)
inline

Sets the WorldObject's x an y coordinate.

Definition at line 70 of file WorldObject.h.

void WorldObject::setTransparency ( float  f)
inline

Sets the WorldObject's transparency.

Parameters
fThe WorldObject's transparancy [0,1] other values will be force set

Definition at line 120 of file WorldObject.h.

void WorldObject::setVelocity ( Point2D  vel)
inline

Sets the WorldObject's velocity as a vector (will set MaxVelocity if needed)

Parameters
velVelocity in (x,y) coords

Definition at line 142 of file WorldObject.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WorldObject::setVelocity ( double  xVel,
double  yVel 
)
inline

Sets the WorldObject's velocity from coordinates (will set MaxVelocity if needed)

Parameters
xVelVelocity x coord
yVelVelocity y coord

Definition at line 154 of file WorldObject.h.

+ Here is the call graph for this function:

void WorldObject::setZOrder ( int  i)
inline

Definition at line 222 of file WorldObject.h.

void WorldObject::update ( )
virtual

Update to run each loop.

Todo:
Handle basic physics here or just do in all inheriting classes (probably better to do later). Make sure to implement velocity and acceleration correctly

Reimplemented in ParticleSystem, Sprite, Text, Background, and Menu.

Definition at line 27 of file WorldObject.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Point2D WorldObject::mAcceleration
protected

The current acceleration vector.

Definition at line 262 of file WorldObject.h.

float WorldObject::mAngle
protected

Angle of rotation.

Definition at line 268 of file WorldObject.h.

Behavior WorldObject::mBehavior
protected

Behavior to act each loop if !mUnused.

Definition at line 280 of file WorldObject.h.

long WorldObject::mLastDraw
protected

Number that indicates when the Object has last updated. Overflows in about 24 days so no worries.

Definition at line 276 of file WorldObject.h.

long WorldObject::mLastUpdate
protected

Number that indicates when the Object has last updated. Overflows in about 24 days so no worries.

Definition at line 274 of file WorldObject.h.

double WorldObject::mMaxSpeed
protected

The max Speed if MaxVelocity is 0 to store val.

Definition at line 260 of file WorldObject.h.

Point2D WorldObject::mMaxVelocity
protected

The max velocity is the max possible velocity where lengthis the speed.

Definition at line 258 of file WorldObject.h.

std::string WorldObject::mName
protected

WorldObject's name.

Definition at line 252 of file WorldObject.h.

Point2D WorldObject::mPos
protected

The current (x,y) position.

Definition at line 254 of file WorldObject.h.

float WorldObject::mScale
protected

Scale for the sprit.

Definition at line 270 of file WorldObject.h.

float WorldObject::mTransparency
protected

Transparency!

Definition at line 266 of file WorldObject.h.

bool WorldObject::mUnused
protected

Determines whether or not this object's update function should run.

Definition at line 278 of file WorldObject.h.

Point2D WorldObject::mVelocity
protected

The current velocity vector.

Todo:
split into magnitude and direction (can use more efficienct computation of values since they are obtainable)

Definition at line 256 of file WorldObject.h.

bool WorldObject::mVisible
protected

Determine if Object should be visible.

Definition at line 264 of file WorldObject.h.

int WorldObject::ZOrder
protected

Stacking order. Determines what draws on top. (subsorted by position)

Definition at line 272 of file WorldObject.h.


The documentation for this class was generated from the following files: