qaf::PlatformerObj Class Reference

#include <qafPlatformerObj.h>

Inheritance diagram for qaf::PlatformerObj:

qaf::GameObj List of all members.

Detailed Description

This is a ready-made game object which controls like a platformer.

You may control the character's parameters (speed, jump height, etc.) through its public fields (marked in ALL CAPS).

The render() method simply displays a set of lines, illustrating the boundaries used for contact testing against the obstacle layer (in blue/red) and the collision structure (in yellow). You may override it in a subclass to display your own sprites.

The platformer is represented by a rectangle with dimensions WIDTHxHEIGHT. Its position (the "hot spot," if you will), is placed at the center of the rectangle's bottom segment. Visually, the strucure looks like this:

           ___
 topLeft  |   | topRight
          |   |
          |   |
  botLeft |___| botRight
            ^
           pos


Public Member Functions

 PlatformerObj (float x, float y, PlatformerInput *platformerInput, AttributeTable &attributes=AttributeTable())
 Constructor: If an attribute table is supplied, the constructor will use its keys to initialize the platformer's parameters (the members in ALL CAPS).
void initialize ()
 Centers the scrolling point on the character.
void update (int objLayer, float dt)
 Updates the character's position, velocity, and sets the contact status.
void render (int objLayer, float scrollX, float scrollY)
 Draws a rectangle displaying the character's bounds, contact status, and direction.
CollisionStructgetCollisionStruct ()
 Returns a collision structure delimited by the platformerObj's position, width and height.
const Vector2DgetPos ()
 Returns the current position of the platformer character.
void setPos (float x, float y)
 Sets the platformer's position.
void translate (float dx, float dy)
 Modifies the platformer's position.
const Vector2DgetVel ()
 Returns the current velocity of the platformer character.
void setVel (float x, float y)
 Sets the platformer's velocity.
bool isUnderwater ()
 Returns true if the platformer is submerged.
bool isFloatingOnWaterSurface ()
 Returns true if the platformer is floating on the water's surface.

Public Attributes

PlatformerInputplatformerInput
 Input structure for this platformer character.
float WIDTH
 The character's width, in pixels.
float HEIGHT
 The character's height, in pixels.
float CAMERA_DX
 The point where the camera will focus.
float CAMERA_DY
 The point where the camera will focus.
float CAMERA_STICKINESS
 The camera does not "stick" to the character, but rather is attracted to it.
bool CENTER_SCROLLING_ON_SELF
 If this flag is set to false, the object will not change the scrolling point in its update() method.
float WALK_SPEED
 The character's maximum walk speed, in pixels/second.
float CLIMB_26_SLOPE_SLOWDOWN
 This factor is used to slow down the character when he is walking up a slope with 26-degree inclination.
float CLIMB_45_SLOPE_SLOWDOWN
 This factor is used to slow down the character when he is walking up a slope with 45-degree inclination.
float WALK_ACCELERATION
 The acceleration applied to the X speed as the player keeps pressing the walk keys, in pixels/second2.
float WALK_DECELERATION
 The deceleration applied to the X speed as the player releases walk keys, in pixels/second2.
float JUMP_STRENGTH
 The Y speed applied when the player jumps on the ground, in pixels/second.
float WATER_JUMP_STRENGTH
 The Y speed applied when the player jumps on the water's surface, in pixels/second.
float GRAVITY
 The acceleration applied to the Y speed when the player is falling, in pixels/second2.
float MAX_FALL_SPEED
 When falling, the Y speed will be clamped to this value.
float SUBMERSION_HEIGHT
 This indicates how much of the character will be submerged when floating on the water's surface.
float BUOYANCY
 "Reverse gravity" applied to the character when underwater, in pixels/second2.
float MAX_FLOAT_SPEED
 When floating upwards the Y speed will be clamped to this value.
float MAX_SINK_SPEED
 When sinking downwards the Y speed will be clamped to this value.
float SWIM_SPEED
 The character's maximum swimming X speed, in pixels/second.
float SWIM_ACCELERATION
 The acceleration applied to the X speed as the player keeps pressing the walk keys while underwater, in pixels/second2.
float SWIM_DECELERATION
 The deceleration applied to the X speed as the player releases walk keys while underwater, in pixels/second2.
bool FLOAT_ON_WATER_SURFACE
 You may turn off the underwater mechanics by setting this flag to false.
bool isFacingLeft
 This flag is set by the update() method, indicating which way the character should be facing when its sprites are rendered.
bool rightContact
 These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.
bool leftContact
 These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.
bool topContact
 These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.
bool bottomContact
 These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.

Classes

class  PlatformerInput
 Represents input for a platformer player. More...


Constructor & Destructor Documentation

qaf::PlatformerObj::PlatformerObj ( float  x,
float  y,
PlatformerInput platformerInput,
AttributeTable attributes = AttributeTable() 
)

Constructor: If an attribute table is supplied, the constructor will use its keys to initialize the platformer's parameters (the members in ALL CAPS).

The keys must have the same name as their corresponding members, and the values must be convertible to floating-point numbers. (The boolean parameters must be the strings "true" or "false.")

Any parameter that cannot be initialized will receive a default value:

 HEIGHT                   =  55;
 WIDTH                    =  10;
 
 CAMERA_DX                =   0;
 CAMERA_DY                = -45;
 
 CAMERA_STICKINESS        =   0.7f;
 
 CENTER_SCROLLING_ON_SELF = false;
 
 WALK_SPEED               = 120.0f;
 
 CLIMB_26_SLOPE_SLOWDOWN  =   1.0f;
 CLIMB_45_SLOPE_SLOWDOWN  =   0.5f;
 
 WALK_ACCELERATION        = 900.0f;
 WALK_DECELERATION        = 900.0f;
 
 JUMP_STRENGTH            = 240.0f;
 WATER_JUMP_STRENGTH      = 195.0f;
 GRAVITY                  = 390.5f;
 MAX_FALL_SPEED           = 330.0f;
 
 SUBMERSION_HEIGHT        =  35.0f;
 BUOYANCY                 = 450.0f;
 MAX_FLOAT_SPEED          =  60.0f;
 MAX_SINK_SPEED           = 150.0f;
 SWIM_SPEED               =  90.0f;
 SWIM_ACCELERATION        = 225.0f;
 SWIM_DECELERATION        = 225.0f;


Member Function Documentation

void qaf::PlatformerObj::update ( int  objLayer,
float  dt 
) [virtual]

Updates the character's position, velocity, and sets the contact status.

It will also center the scrolling point on the character and update the collision structure.

Reimplemented from qaf::GameObj.

void qaf::PlatformerObj::render ( int  objLayer,
float  scrollX,
float  scrollY 
) [virtual]

Draws a rectangle displaying the character's bounds, contact status, and direction.

Intended for debug purposes.

Reimplemented from qaf::GameObj.

const Vector2D& qaf::PlatformerObj::getPos (  )  [inline]

Returns the current position of the platformer character.

This is a const reference, so you can call this method as much as you like without performance penalties.

const Vector2D& qaf::PlatformerObj::getVel (  )  [inline]

Returns the current velocity of the platformer character.

This is a const reference, so you can call this method as much as you like without performance penalties.


Member Data Documentation

PlatformerInput* qaf::PlatformerObj::platformerInput

Input structure for this platformer character.

If the pointer is set to NULL, the character will stop receiving input, but will still update its state (falling, floating in the water, etc.).

float qaf::PlatformerObj::WIDTH

The character's width, in pixels.

See also:
HEIGHT

float qaf::PlatformerObj::HEIGHT

The character's height, in pixels.

See also:
WIDTH

float qaf::PlatformerObj::CAMERA_DX

The point where the camera will focus.

This is a displacement relative to the character's base point.

See also:
CAMERA_DY

float qaf::PlatformerObj::CAMERA_DY

The point where the camera will focus.

This is a displacement relative to the character's base point.

See also:
CAMERA_DY

float qaf::PlatformerObj::CAMERA_STICKINESS

The camera does not "stick" to the character, but rather is attracted to it.

This parameter controls how fast it will follow the player's movements. Specify a value in the [0, 1] range.

To make the camera "stick" to the character (i.e., it will always be at the player's position), you may set

See also:
CENTER_SCROLLING_ON_SELF

bool qaf::PlatformerObj::CENTER_SCROLLING_ON_SELF

If this flag is set to false, the object will not change the scrolling point in its update() method.

See also:
CAMERA_STICKINESS

float qaf::PlatformerObj::WALK_SPEED

The character's maximum walk speed, in pixels/second.

(Specify a number greater than zero; the object will adjust the sign as needed.)

float qaf::PlatformerObj::CLIMB_26_SLOPE_SLOWDOWN

This factor is used to slow down the character when he is walking up a slope with 26-degree inclination.

Specify a number in the range [0, 1].

 CLIMB_26_SLOPE_SLOWDOWN = 1.0; // Walks at normal speed when climbing 26-degree slopes

See also:
CLIMB_45_SLOPE_SLOWDOWN

float qaf::PlatformerObj::CLIMB_45_SLOPE_SLOWDOWN

This factor is used to slow down the character when he is walking up a slope with 45-degree inclination.

Specify a number in the range [0, 1].

 CLIMB_45_SLOPE_SLOWDOWN = 0.5; // Walks at half speed when climbing 45-degree slopes

See also:
CLIMB_26_SLOPE_SLOWDOWN

float qaf::PlatformerObj::WALK_ACCELERATION

The acceleration applied to the X speed as the player keeps pressing the walk keys, in pixels/second2.

(Specify numbers greater than zero; the object will adjust the sign as needed.)

See also:
WALK_DECELERATION

float qaf::PlatformerObj::WALK_DECELERATION

The deceleration applied to the X speed as the player releases walk keys, in pixels/second2.

(Specify numbers greater than zero; the object will adjust the sign as needed.)

See also:
WALK_ACCELERATION

float qaf::PlatformerObj::JUMP_STRENGTH

The Y speed applied when the player jumps on the ground, in pixels/second.

(Specify a number greater than zero; the object will adjust the sign as needed.)

See also:
WATER_JUMP_STRENGTH

float qaf::PlatformerObj::WATER_JUMP_STRENGTH

The Y speed applied when the player jumps on the water's surface, in pixels/second.

(Specify a number greater than zero; the object will adjust the sign as needed.)

See also:
JUMP_STRENGTH

float qaf::PlatformerObj::GRAVITY

The acceleration applied to the Y speed when the player is falling, in pixels/second2.

float qaf::PlatformerObj::MAX_FALL_SPEED

When falling, the Y speed will be clamped to this value.

float qaf::PlatformerObj::SUBMERSION_HEIGHT

This indicates how much of the character will be submerged when floating on the water's surface.

      ____
     |    |
 ~~~~~~~~~~~~~~~~ /
     |    |       |
     |    |       | Subm. height
     |    |       |
     |____|       /

float qaf::PlatformerObj::BUOYANCY

"Reverse gravity" applied to the character when underwater, in pixels/second2.

(Specify a number greater than zero; the object will adjust the sign as needed.)

float qaf::PlatformerObj::MAX_FLOAT_SPEED

When floating upwards the Y speed will be clamped to this value.

(Specify a number greater than zero; the object will adjust the sign as needed.)

See also:
MAX_SINK_SPEED

float qaf::PlatformerObj::MAX_SINK_SPEED

When sinking downwards the Y speed will be clamped to this value.

(Specify a number greater than zero; the object will adjust the sign as needed.)

See also:
MAX_FLOAT_SPEED

float qaf::PlatformerObj::SWIM_SPEED

The character's maximum swimming X speed, in pixels/second.

(Specify a number greater than zero; the object will adjust the sign as needed.)

float qaf::PlatformerObj::SWIM_ACCELERATION

The acceleration applied to the X speed as the player keeps pressing the walk keys while underwater, in pixels/second2.

(Specify numbers greater than zero; the object will adjust the signs as needed.)

See also:
SWIM_DECELERATION

float qaf::PlatformerObj::SWIM_DECELERATION

The deceleration applied to the X speed as the player releases walk keys while underwater, in pixels/second2.

(Specify numbers greater than zero; the object will adjust the signs as needed.)

See also:
SWIM_ACCELERATION

bool qaf::PlatformerObj::FLOAT_ON_WATER_SURFACE

You may turn off the underwater mechanics by setting this flag to false.

The character will behave as though there were no water at all.

bool qaf::PlatformerObj::isFacingLeft

This flag is set by the update() method, indicating which way the character should be facing when its sprites are rendered.

bool qaf::PlatformerObj::rightContact

These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.

See also:
rightContact, leftContact, topContact, bottomContact

bool qaf::PlatformerObj::leftContact

These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.

See also:
rightContact, leftContact, topContact, bottomContact

bool qaf::PlatformerObj::topContact

These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.

See also:
rightContact, leftContact, topContact, bottomContact

bool qaf::PlatformerObj::bottomContact

These flags are set by the update() method, and indicate which segments are touching walls, floors and ceilings.

See also:
rightContact, leftContact, topContact, bottomContact


The documentation for this class was generated from the following file:
Generated on Sun Mar 25 12:32:14 2007 for Qaf Framework by  doxygen 1.5.1-p1