#include <qafPlatformerObj.h>
Inheritance diagram for qaf::PlatformerObj:
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 WIDTH
xHEIGHT
. 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. | |
CollisionStruct * | getCollisionStruct () |
Returns a collision structure delimited by the platformerObj's position, width and height. | |
const Vector2D & | getPos () |
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 Vector2D & | getVel () |
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 | |
PlatformerInput * | platformerInput |
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... |
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;
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.
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.).
The point where the camera will focus.
This is a displacement relative to the character's base point.
The point where the camera will focus.
This is a displacement relative to the character's base point.
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
CAMERA_STICKINESS = 1;
If this flag is set to false, the object will not change the scrolling point in its update()
method.
The character's maximum walk speed, in pixels/second.
(Specify a number greater than zero; the object will adjust the sign as needed.)
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
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
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.)
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.)
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.)
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.)
The acceleration applied to the Y speed when the player is falling, in pixels/second2.
When falling, the Y speed will be clamped to this value.
This indicates how much of the character will be submerged when floating on the water's surface.
____ | | ~~~~~~~~~~~~~~~~ / | | | | | | Subm. height | | | |____| /
"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.)
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.)
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.)
The character's maximum swimming X speed, in pixels/second.
(Specify a number greater than zero; the object will adjust the sign as needed.)
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.)
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.)
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.
This flag is set by the update()
method, indicating which way the character should be facing when its sprites are rendered.
These flags are set by the update()
method, and indicate which segments are touching walls, floors and ceilings.
These flags are set by the update()
method, and indicate which segments are touching walls, floors and ceilings.
These flags are set by the update()
method, and indicate which segments are touching walls, floors and ceilings.
These flags are set by the update()
method, and indicate which segments are touching walls, floors and ceilings.