hoa_map::private_map::MapObject Class Reference

Abstract class that represents objects on a map. More...

#include <map_objects.h>

Inheritance diagram for hoa_map::private_map::MapObject:

Inheritance graph
[legend]
Collaboration diagram for hoa_map::private_map::MapObject:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual void Draw ()=0
 Draws the object to the frame buffer. Objects are drawn differently depending on what type of object they are and what their current state is. This function is only called for objects that will be visible on the screen when drawn and have their VISIBLE bit in the MapObject::_status member set.
bool DrawHelper ()
 Assists with the drawing of map objects.
 MapObject ()
virtual void Update ()=0
 Updates the state of an object. Many map objects may not actually have a use for this function. For example, animated objects like a tree automatically have their frames updated by the video engine, so there is no need to call this function for it. The function is only called for objects which have the UPDATEABLE bit in the MapObject::_status member set.
virtual ~MapObject ()
float ComputeXLocation () const
 Computes the full floating-point location coordinates of the object.
float ComputeYLocation () const
Lua Access Functions
These functions are specifically written for Lua binding, to enable Lua to access the members of this class.

float GetCollHalfWidth () const
float GetCollHeight () const
uint32 GetContext () const
float GetImgHalfWidth () const
float GetImgHeight () const
int16 GetObjectID () const
uint8 GetType () const
void GetXPosition (uint16 &x, float &offset) const
void GetYPosition (uint16 &y, float &offset) const
bool IsDrawOnSecondPass () const
bool IsNoCollision () const
bool IsUpdatable () const
bool IsVisible () const
void SetCollHalfWidth (float collision)
void SetCollHeight (float collision)
void SetContext (uint32 ctxt)
void SetDrawOnSecondPass (bool pass)
void SetImgHalfWidth (float width)
void SetImgHeight (float height)
void SetNoCollision (bool coll)
void SetObjectID (int16 id=0)
void SetUpdatable (bool update)
void SetVisible (bool vis)
void SetXPosition (uint16 x, float offset)
void SetYPosition (uint16 y, float offset)

Public Attributes

float coll_half_width
 Determines the collision rectangle for the object. The collision area determines what portion of the map object may not be overlapped by other objects or unwalkable regions of the map. The x and y coordinates are relative to the origin, so an x value of 0.5f means that the collision rectangle extends the length of 1/2 of a tile from the origin on both sides, and a y value of 1.0f means that the collision area exists from the origin to 1 tile's length above.
float coll_height
uint32 context
 The map context that the object currently resides in. Context helps to determine where an object "resides". For example, inside of a house or outside of a house. The context member determines if the object should be drawn or not, since objects are only drawn if they are in the same context as the map's camera. Objects can only interact with one another if they both reside in the same context.
bool draw_on_second_pass
 When set to true, objects in the ground object layer will be drawn after the pass objects.
std::string filename
float img_half_width
 The half-width and height of the image, in map grid coordinates. The half_width member is indeed just that: half the width of the object's image. We keep the half width rather than the full width because the origin of the object is its bottom center, and it is more convenient to store only half the sprite's width as a result.
float img_height
bool no_collision
 When set to true, the object will not be examined for collision detection (default = false). Setting this member to true really has two effects. First, the object may exist anywhere on the map, including where the collision rectangles of other objects are located. Second, the object is ignored when other objects are performing their collision detection. This property is useful for virtual objects or objects with an image but no "physical form" (i.e. ghosts that other sprites may walk through). Note that while this member is set to true, the object's collision rectangle members are ignored.
int16 object_id
 An identification number for the object as it is represented in the map file. Player sprites are assigned object ids from 5000 and above. Technically this means that a map can have no more than 5000 objects that are not player sprites, but no map should need to contain that many objects in the first place. Objects with an ID less than zero are invalid.
bool updatable
 When set to false, the Update() function will do nothing (default = true).
bool visible
 When set to false, the Draw() function will do nothing (default = true).
float x_offset
uint16 x_position
 Coordinates for the object's origin/position. The origin of every map object is the bottom center point of the object. These origin coordinates are used to determine where the object is on the map as well as where the objects collision rectangle lies.
float y_offset
uint16 y_position

Protected Attributes

uint8 _object_type
 This holds the the type of sprite this is.

Detailed Description

Abstract class that represents objects on a map.

****************************************************************************

A map object can be anything from a sprite to a tree to a house. To state it simply, a map object is a map image that is not tiled and may not be fixed in place. Map objects are drawn in one of three layers: ground, pass, and sky object layers. Every map object has a collision rectangle associated with it. The collision rectangle indicates what parts of the object may not overlap with other collision rectangles.

Note:
It is advised not to attempt to make map objects with dynamic sizes (i.e. the various image frames that compose the object are all the same size). In theory, dynamically sized objects are feasible to implement in maps, but they are much more vulnerable to bugs

Definition at line 53 of file map_objects.h.


Constructor & Destructor Documentation

hoa_map::private_map::MapObject::MapObject (  ) 

Definition at line 45 of file map_objects.cpp.

virtual hoa_map::private_map::MapObject::~MapObject (  )  [inline, virtual]

Definition at line 147 of file map_objects.h.


Member Function Documentation

float hoa_map::private_map::MapObject::ComputeXLocation (  )  const [inline]

Computes the full floating-point location coordinates of the object.

Returns:
The full x or y coordinate location of the object
Since an object's position is stored as an integer component and an offset component, this method simply returns a single floating point value representing the full x and y positions of the object in a single variable.

Definition at line 183 of file map_objects.h.

References x_offset, and x_position.

Referenced by hoa_map::MapMode::_CalculateDrawInfo(), hoa_map::MapMode::_DetectCollision(), hoa_map::MapMode::_FindNearestObject(), hoa_map::private_map::EnemySprite::Update(), and hoa_map::private_map::VirtualSprite::Update().

float hoa_map::private_map::MapObject::ComputeYLocation (  )  const [inline]

Definition at line 186 of file map_objects.h.

References y_offset, and y_position.

Referenced by hoa_map::MapMode::_CalculateDrawInfo(), hoa_map::MapMode::_DetectCollision(), hoa_map::MapMode::_FindNearestObject(), hoa_map::private_map::EnemySprite::Update(), and hoa_map::private_map::VirtualSprite::Update().

virtual void hoa_map::private_map::MapObject::Draw (  )  [pure virtual]

Draws the object to the frame buffer. Objects are drawn differently depending on what type of object they are and what their current state is. This function is only called for objects that will be visible on the screen when drawn and have their VISIBLE bit in the MapObject::_status member set.

Implemented in hoa_map::private_map::PhysicalObject, hoa_map::private_map::VirtualSprite, hoa_map::private_map::MapSprite, and hoa_map::private_map::EnemySprite.

bool hoa_map::private_map::MapObject::DrawHelper (  ) 

Assists with the drawing of map objects.

Returns:
True if the object should be drawn, or false if it is not visible on the screen.
This method performs the common drawing operations of identifying whether or not the object is visible on the screen and moving the drawing cursor to its location. The children classes of this class may choose to make use of it (or not). All that needs to be done after this method returns true is to draw the object's image on the screen.

Definition at line 64 of file map_objects.cpp.

References hoa_map::MapMode::_current_map, hoa_map::MapMode::_draw_info, hoa_map::private_map::MapFrame::bottom_edge, img_half_width, img_height, hoa_video::GameVideo::Move(), hoa_map::private_map::MapFrame::right_edge, hoa_map::private_map::MapFrame::top_edge, hoa_video::VideoManager, visible, x_offset, x_position, y_offset, and y_position.

Referenced by hoa_map::private_map::EnemySprite::Draw(), hoa_map::private_map::MapSprite::Draw(), and hoa_map::private_map::PhysicalObject::Draw().

Here is the call graph for this function:

float hoa_map::private_map::MapObject::GetCollHalfWidth (  )  const [inline]

Definition at line 249 of file map_objects.h.

References coll_half_width.

float hoa_map::private_map::MapObject::GetCollHeight (  )  const [inline]

Definition at line 252 of file map_objects.h.

References coll_height.

uint32 hoa_map::private_map::MapObject::GetContext (  )  const [inline]

Definition at line 234 of file map_objects.h.

References context.

float hoa_map::private_map::MapObject::GetImgHalfWidth (  )  const [inline]

Definition at line 243 of file map_objects.h.

References img_half_width.

float hoa_map::private_map::MapObject::GetImgHeight (  )  const [inline]

Definition at line 246 of file map_objects.h.

References img_height.

Referenced by hoa_map::private_map::VirtualSprite::Draw().

int16 hoa_map::private_map::MapObject::GetObjectID (  )  const [inline]

Definition at line 231 of file map_objects.h.

References object_id.

uint8 hoa_map::private_map::MapObject::GetType (  )  const [inline]

Definition at line 267 of file map_objects.h.

References _object_type.

void hoa_map::private_map::MapObject::GetXPosition ( uint16 x,
float &  offset 
) const [inline]

Definition at line 237 of file map_objects.h.

References x_offset, and x_position.

void hoa_map::private_map::MapObject::GetYPosition ( uint16 y,
float &  offset 
) const [inline]

Definition at line 240 of file map_objects.h.

References y_offset, and y_position.

bool hoa_map::private_map::MapObject::IsDrawOnSecondPass (  )  const [inline]

Definition at line 264 of file map_objects.h.

References draw_on_second_pass.

bool hoa_map::private_map::MapObject::IsNoCollision (  )  const [inline]

Definition at line 261 of file map_objects.h.

References no_collision.

bool hoa_map::private_map::MapObject::IsUpdatable (  )  const [inline]

Definition at line 255 of file map_objects.h.

References updatable.

bool hoa_map::private_map::MapObject::IsVisible (  )  const [inline]

Definition at line 258 of file map_objects.h.

References visible.

void hoa_map::private_map::MapObject::SetCollHalfWidth ( float  collision  )  [inline]

Definition at line 213 of file map_objects.h.

References coll_half_width.

void hoa_map::private_map::MapObject::SetCollHeight ( float  collision  )  [inline]

Definition at line 216 of file map_objects.h.

References coll_height.

void hoa_map::private_map::MapObject::SetContext ( uint32  ctxt  )  [inline]

Definition at line 198 of file map_objects.h.

References context.

void hoa_map::private_map::MapObject::SetDrawOnSecondPass ( bool  pass  )  [inline]

Definition at line 228 of file map_objects.h.

References draw_on_second_pass.

void hoa_map::private_map::MapObject::SetImgHalfWidth ( float  width  )  [inline]

Definition at line 207 of file map_objects.h.

References img_half_width.

void hoa_map::private_map::MapObject::SetImgHeight ( float  height  )  [inline]

Definition at line 210 of file map_objects.h.

References img_height.

void hoa_map::private_map::MapObject::SetNoCollision ( bool  coll  )  [inline]

Definition at line 225 of file map_objects.h.

References no_collision.

void hoa_map::private_map::MapObject::SetObjectID ( int16  id = 0  )  [inline]

Definition at line 195 of file map_objects.h.

References object_id.

Referenced by hoa_map::private_map::EnemyZone::AddEnemy().

void hoa_map::private_map::MapObject::SetUpdatable ( bool  update  )  [inline]

Definition at line 219 of file map_objects.h.

References updatable.

void hoa_map::private_map::MapObject::SetVisible ( bool  vis  )  [inline]

Definition at line 222 of file map_objects.h.

References visible.

void hoa_map::private_map::MapObject::SetXPosition ( uint16  x,
float  offset 
) [inline]

Definition at line 201 of file map_objects.h.

References x_offset, and x_position.

void hoa_map::private_map::MapObject::SetYPosition ( uint16  y,
float  offset 
) [inline]

Definition at line 204 of file map_objects.h.

References y_offset, and y_position.

virtual void hoa_map::private_map::MapObject::Update (  )  [pure virtual]

Updates the state of an object. Many map objects may not actually have a use for this function. For example, animated objects like a tree automatically have their frames updated by the video engine, so there is no need to call this function for it. The function is only called for objects which have the UPDATEABLE bit in the MapObject::_status member set.

Implemented in hoa_map::private_map::PhysicalObject, hoa_map::private_map::VirtualSprite, hoa_map::private_map::MapSprite, and hoa_map::private_map::EnemySprite.


Member Data Documentation

uint8 hoa_map::private_map::MapObject::_object_type [protected]

This holds the the type of sprite this is.

Definition at line 273 of file map_objects.h.

Referenced by hoa_map::private_map::EnemySprite::EnemySprite(), GetType(), hoa_map::private_map::MapSprite::MapSprite(), hoa_map::private_map::PhysicalObject::PhysicalObject(), and hoa_map::private_map::VirtualSprite::VirtualSprite().

float hoa_map::private_map::MapObject::coll_half_width

Determines the collision rectangle for the object. The collision area determines what portion of the map object may not be overlapped by other objects or unwalkable regions of the map. The x and y coordinates are relative to the origin, so an x value of 0.5f means that the collision rectangle extends the length of 1/2 of a tile from the origin on both sides, and a y value of 1.0f means that the collision area exists from the origin to 1 tile's length above.

Note:
These members should always be positive. Setting these members to zero does *not* eliminate collision detection for the object, and therefore they should usually never be zero.

Definition at line 117 of file map_objects.h.

Referenced by hoa_map::MapMode::_DetectCollision(), hoa_map::MapMode::_FindNearestObject(), GetCollHalfWidth(), and SetCollHalfWidth().

float hoa_map::private_map::MapObject::coll_height

Definition at line 117 of file map_objects.h.

Referenced by hoa_map::MapMode::_DetectCollision(), hoa_map::MapMode::_FindNearestObject(), GetCollHeight(), and SetCollHeight().

uint32 hoa_map::private_map::MapObject::context

The map context that the object currently resides in. Context helps to determine where an object "resides". For example, inside of a house or outside of a house. The context member determines if the object should be drawn or not, since objects are only drawn if they are in the same context as the map's camera. Objects can only interact with one another if they both reside in the same context.

Note:
The default value for this member is -1. A negative context indicates that the object is invalid and it does not exist anywhere. Objects with a negative context are never drawn to the screen. A value equal to zero indicates that the object is "always in context", meaning that the object will be drawn regardless of the current context. An example of where this is useful is a bridge, which shouldn't simply disappear because the player walks inside a nearby home.

Definition at line 76 of file map_objects.h.

Referenced by hoa_map::MapMode::_DetectCollision(), hoa_map::MapMode::_FindNearestObject(), GetContext(), and SetContext().

bool hoa_map::private_map::MapObject::draw_on_second_pass

When set to true, objects in the ground object layer will be drawn after the pass objects.

Note:
This member is only checked for objects that exist in the ground layer. It has no meaning for objects in the pass or sky layers.

Definition at line 139 of file map_objects.h.

Referenced by IsDrawOnSecondPass(), and SetDrawOnSecondPass().

std::string hoa_map::private_map::MapObject::filename

Definition at line 141 of file map_objects.h.

Referenced by hoa_map::private_map::EnemySprite::EnemySprite(), and hoa_map::private_map::EnemySprite::Load().

float hoa_map::private_map::MapObject::img_half_width

The half-width and height of the image, in map grid coordinates. The half_width member is indeed just that: half the width of the object's image. We keep the half width rather than the full width because the origin of the object is its bottom center, and it is more convenient to store only half the sprite's width as a result.

Note:
These members assume that the object retains the same width and height regardless of the current animation or image being drawn. If the object's image changes size, the API user must remember to change these values accordingly.

Definition at line 103 of file map_objects.h.

Referenced by DrawHelper(), GetImgHalfWidth(), hoa_map::private_map::MapSprite::LoadStandardAnimations(), and SetImgHalfWidth().

float hoa_map::private_map::MapObject::img_height

Definition at line 103 of file map_objects.h.

Referenced by DrawHelper(), GetImgHeight(), hoa_map::private_map::MapSprite::LoadStandardAnimations(), and SetImgHeight().

bool hoa_map::private_map::MapObject::no_collision

When set to true, the object will not be examined for collision detection (default = false). Setting this member to true really has two effects. First, the object may exist anywhere on the map, including where the collision rectangles of other objects are located. Second, the object is ignored when other objects are performing their collision detection. This property is useful for virtual objects or objects with an image but no "physical form" (i.e. ghosts that other sprites may walk through). Note that while this member is set to true, the object's collision rectangle members are ignored.

Definition at line 133 of file map_objects.h.

Referenced by hoa_map::MapMode::_DetectCollision(), hoa_map::private_map::EnemySprite::ChangeStateHostile(), hoa_map::private_map::EnemySprite::ChangeStateSpawning(), IsNoCollision(), hoa_map::private_map::EnemySprite::Reset(), and SetNoCollision().

int16 hoa_map::private_map::MapObject::object_id

An identification number for the object as it is represented in the map file. Player sprites are assigned object ids from 5000 and above. Technically this means that a map can have no more than 5000 objects that are not player sprites, but no map should need to contain that many objects in the first place. Objects with an ID less than zero are invalid.

Definition at line 61 of file map_objects.h.

Referenced by hoa_map::MapMode::_AddGroundObject(), hoa_map::MapMode::_AddPassObject(), hoa_map::MapMode::_AddSkyObject(), GetObjectID(), and SetObjectID().

bool hoa_map::private_map::MapObject::updatable

When set to false, the Update() function will do nothing (default = true).

Definition at line 120 of file map_objects.h.

Referenced by hoa_map::private_map::EnemySprite::ChangeStateHostile(), hoa_map::private_map::EnemySprite::ChangeStateSpawning(), IsUpdatable(), hoa_map::private_map::EnemySprite::Reset(), SetUpdatable(), hoa_map::private_map::VirtualSprite::Update(), and hoa_map::private_map::PhysicalObject::Update().

bool hoa_map::private_map::MapObject::visible

When set to false, the Draw() function will do nothing (default = true).

Definition at line 123 of file map_objects.h.

Referenced by DrawHelper(), IsVisible(), and SetVisible().

float hoa_map::private_map::MapObject::x_offset

Definition at line 91 of file map_objects.h.

Referenced by hoa_map::MapMode::_CalculateDrawInfo(), ComputeXLocation(), DrawHelper(), GetXPosition(), SetXPosition(), and hoa_map::private_map::VirtualSprite::Update().

uint16 hoa_map::private_map::MapObject::x_position

Coordinates for the object's origin/position. The origin of every map object is the bottom center point of the object. These origin coordinates are used to determine where the object is on the map as well as where the objects collision rectangle lies.

The position coordinates are described by an integer (position) and a float (offset). The position coordinates point to the map grid tile that the object currently occupies and may range from 0 to the number of columns or rows of grid tiles on the map. The offset member will always range from 0.0f and 1.0f to indicate the exact position of the object within that tile.

Definition at line 90 of file map_objects.h.

Referenced by hoa_map::MapMode::_CalculateDrawInfo(), ComputeXLocation(), DrawHelper(), hoa_map::private_map::ActionPathMove::Execute(), GetXPosition(), SetXPosition(), hoa_map::private_map::EnemySprite::Update(), and hoa_map::private_map::VirtualSprite::Update().

float hoa_map::private_map::MapObject::y_offset

Definition at line 91 of file map_objects.h.

Referenced by hoa_map::MapMode::_CalculateDrawInfo(), ComputeYLocation(), DrawHelper(), GetYPosition(), hoa_map::private_map::MapObject_Ptr_Less::operator()(), SetYPosition(), and hoa_map::private_map::VirtualSprite::Update().

uint16 hoa_map::private_map::MapObject::y_position

Definition at line 90 of file map_objects.h.

Referenced by hoa_map::MapMode::_CalculateDrawInfo(), ComputeYLocation(), DrawHelper(), hoa_map::private_map::ActionPathMove::Execute(), GetYPosition(), hoa_map::private_map::MapObject_Ptr_Less::operator()(), SetYPosition(), hoa_map::private_map::EnemySprite::Update(), and hoa_map::private_map::VirtualSprite::Update().


The documentation for this class was generated from the following files:
Generated on Fri Jul 6 23:14:53 2007 for Hero of Allacrost by  doxygen 1.5.1