Propane::Game2D::Actor Class Reference

A 2D actor with animation and rotation support. Used in Freezer 2 and Glow. More...

#include <PropaneActor.h>

List of all members.

Public Member Functions

 Actor (SpriteManager *sprites)
 Create with a given sprite manager as parent.
virtual ~Actor ()
 Destructor for this actor.
void setAnimation (int startFrame, int numFrames, float frameDelay)
 Allows you to override animation values permanently. This will not affect any temporary frames currently active.
virtual void draw (int x, int y)
 Draw the actor, based on the provided camera coordinate in worldspace. (x,y) is the CENTRE of what the camera is LOOKING AT (i.e. where the camera "is").
virtual void move (float dx, float dy)
 Move the actor some number of world units.
virtual void temporaryFrame (int frame)
 Allows you to temporarily override standard animation, for a single frame. Resets the animation timer.
virtual void resetAnimation ()
 Resets your animation to base values, including resetting the timer and clearing out temporary frames.
virtual bool rotateTowards (double maxRot, double goal)
 Make the actor face a certain angle "over time". Very useful for smooth, human-like turning.
virtual void rotateFacing (float x, float y)
 Forces the actor to instantly turn towards a given (x,y) in worldspace.
float getX ()
 Get the actor's current horizontal (east-west) world coordinate.
float getY ()
 Get the actor's current vertical (north-south) world coordinate.
float getWidth ()
 Get the actor's width in world units. This affects drawing and collision.
float getHeight ()
 Get the actor's height in world units. This affects drawing and collision.
float getForwardX (float delta, float offsetx=0.0f, float offsety=0.0f)
 Gets a point ahead of the actor at "delta" distance. Use offsetx and offsety to get a point on the actor ahead (for example, their hand to place a gun in it).
float getForwardY (float delta, float offsetx=0.0f, float offsety=0.0f)
 Gets a point ahead of the actor at "delta" distance. Use offsetx and offsety to get a point on the actor ahead (for example, their hand to place a gun in it).
virtual double getRotation ()
 Get current actor rotation (in degrees).
virtual double angleTowards (float wx, float wy)
 Get the actor's angle towards a certain location in worldspace.
virtual double angleDistance (double angle1, double angle2)
 Get the arc length required to turn towards a world loc (in terms of degrees).
virtual double angleOutOf360 (double angle)
 Get an angle in degrees out of 360.
void setX (float newX)
 Set the actor's X (horizontal, east-west) coordinate in world units.
void setY (float newY)
 Sets the actor's Y (vertical, north-south) coordinate in world units.
void setWidth (float width)
 Sets actor width in world units, affecting collision and rendering.
void setHeight (float height)
 Sets actor height in world units, affecting collision and rendering.
void setXYWH (float x, float y, float width, float height)
 Sets actor (X,Y) position and dimensions at the same time.
virtual void setRotation (double degrees)
 Instantly sets the actor's rotation to a given angle in degrees.
virtual void rotate (double dRot)
 Changes the actor's current rotation by dRot degrees.
virtual bool collision (Actor *actor2)
 Returns true if it collided with another Actor object. Uses the other object's getX/getY/getWidth/getHeight methods to do so.
int getFrame ()
 Gets the sprite that should be used for rendering this actor's current animation frame.
void updateAnimation (float delta)
 Updates the animation timer, incrementing frames as necessary. Delta is in seconds.
virtual void handleTrigger (std::string trigger_uid)
 For purposes of scripting, take an event trigger UID and perform a variable action on it. Interface method.

Protected Member Functions

float DegToRad (double degree)
 Converts rotations in degrees to radians.
double rotationOutOf360 ()
 Returns the actor's current rotation out of 360 (in degrees).

Protected Attributes

int startFrame
 The first frame in the animation sequence.
float frameTimer
 The amount of time the current frame has spent.
float frameDelay
 The amount of time a frame can take before it advances.
int curFrame
 The offset from the first frame in the series.
int numFrames
 How high the offset can get before it loops back to 0 (first frame).
float x
 X coordinate, world units.
float y
 Y coordinate, world units.
float w
 Width, world units (collision & render).
float h
 Height, world units (collision & render).
double rotation
 Current actor rotation (in degrees).
bool inTemp
 Are we in a temporary frame?
int tempFrame
 The id of the temporary frame.
SpriteManagermyMgr
 A pointer to the sprite manager that will render this actor, including the raw textures that tempFrame/startFrame reference.


Detailed Description

A 2D actor with animation and rotation support. Used in Freezer 2 and Glow.


Constructor & Destructor Documentation

Actor::Actor SpriteManager mgr  ) 
 

Create with a given sprite manager as parent.

Constructs a new Actor that references a given SpriteManager.

In future releases of PI, the requirement to provide a SpriteManager will be lifted and the SpriteManager itself, or another class, will handle actor rendering.

Parameters:
mgr The sprite manager to use for the draw method.

Actor::~Actor  )  [virtual]
 

Destructor for this actor.

Stub destructor. Does nothing.


Member Function Documentation

double Actor::angleDistance double  angle1,
double  angle2
[virtual]
 

Get the arc length required to turn towards a world loc (in terms of degrees).

Get the number of degrees "distance" we have from a given angle.

Parameters:
angle1 The current angle
angle2 The "goal" angle
Returns:
The arc distance from one angle to another

double Actor::angleOutOf360 double  angle  )  [virtual]
 

Get an angle in degrees out of 360.

Convert an angle of any number to [0,360) This just uses fmodf, which is a change from Freezer which implemented it very dumbly with a loop.

Parameters:
angle The non-normalized angle, in degrees.
Returns:
The converted angle, in degrees.

double Actor::angleTowards float  tx,
float  ty
[virtual]
 

Get the actor's angle towards a certain location in worldspace.

Get the angle from an actor to a given location in world space.

Parameters:
tx The x-coordinate of the location in world space.
ty The y-coordinate of the location in world space.
Returns:
The angle, in degrees, from the actor to the world location.
Rotate the target actor to face a specified x,y coordinate in world space.

bool Actor::collision Actor otherActor  )  [virtual]
 

Returns true if it collided with another Actor object. Uses the other object's getX/getY/getWidth/getHeight methods to do so.

Simple AABB collision between two actors.

Parameters:
otherActor the other Actor object to collide with.
Returns:
True if there is AABB overlap, false otherwise.

float Actor::DegToRad double  degrees  )  [protected]
 

Converts rotations in degrees to radians.

Convert degrees to radians.

Parameters:
degrees An angle in degrees
Returns:
The angle in radians.
Converts degrees out of 360 to radians out of 2 PI

void Actor::draw int  px,
int  py
[virtual]
 

Draw the actor, based on the provided camera coordinate in worldspace. (x,y) is the CENTRE of what the camera is LOOKING AT (i.e. where the camera "is").

Renders the actor to screen using its current sprite, rotation, height, width, and location, using the camera (px,py).

To use this method, imagine (px,py) is the point in the centre of the viewport. This is the point you are "looking at" in the world, and the actors will be drawn relative to this point.

Parameters:
px The camera's X position (in world coordinates). The actor will be drawn relative to these.
py The camera's Y position (in world coordinates). The actor will be drawn relative to these.

float Actor::getForwardX float  distance,
float  offsetX = 0.0f,
float  offsetY = 0.0f
 

Gets a point ahead of the actor at "delta" distance. Use offsetx and offsety to get a point on the actor ahead (for example, their hand to place a gun in it).

Get the X-coordinate of the position in world space that is ahead of the actor. Use offsetX/offsetY to manipulate the position on the player that is projected; Glow uses this function to make visible weapons look correct when the player rotates, and to spawn bullets at the correct location relative to the held gun.

Parameters:
distance The distance, in world space, ahead of the player.
offsetX The local vertical offset from the centre of the player actor, in world units.
offsetY The local vertical offset from the centre of the player actor, in world units.
Returns:
The x-coordinate of the position in world space that is ahead of the actor.

float Actor::getForwardY float  distance,
float  offsetX = 0.0f,
float  offsetY = 0.0f
 

Gets a point ahead of the actor at "delta" distance. Use offsetx and offsety to get a point on the actor ahead (for example, their hand to place a gun in it).

Get the Y-coordinate of the position in world space that is ahead of the actor. Use offsetX/offsetY to manipulate the position on the player that is projected; Glow uses this function to make visible weapons look correct when the player rotates, and to spawn bullets at the correct location relative to the held gun.

Parameters:
distance The distance, in world space, ahead of the player.
offsetX The local vertical offset from the centre of the player actor, in world units.
offsetY The local vertical offset from the centre of the player actor, in world units.
Returns:
The Y-coordinate of the position in world space that is ahead of the actor.

int Actor::getFrame  ) 
 

Gets the sprite that should be used for rendering this actor's current animation frame.

Get the current frame being used by the actor, which will be used to render it.

Returns:
The frame ID being used by the actor at this point in time.

float Actor::getHeight  ) 
 

Get the actor's height in world units. This affects drawing and collision.

Get the actor height in the world.

Returns:
The height of the actor, in world units.

double Actor::getRotation  )  [virtual]
 

Get current actor rotation (in degrees).

Get the actor's rotation in degrees.

Returns:
The actor's heading, in degrees.

float Actor::getWidth  ) 
 

Get the actor's width in world units. This affects drawing and collision.

Get the actor width in the world.

Returns:
The width of the actor, in world units.

float Actor::getX  ) 
 

Get the actor's current horizontal (east-west) world coordinate.

Get the actor x-location in the world.

Returns:
The x-location of the actor, in world units.

float Actor::getY  ) 
 

Get the actor's current vertical (north-south) world coordinate.

Get the actor y-location in the world.

Returns:
The y-location of the actor, in world units.

void Actor::move float  dx,
float  dy
[virtual]
 

Move the actor some number of world units.

Moves the actor the specified amount. After this function is finished, the new position will be (x + dx, y + dy)

Parameters:
dx The amount of x to change, in world units
dy The amount of y to change, in world units

void Actor::resetAnimation  )  [virtual]
 

Resets your animation to base values, including resetting the timer and clearing out temporary frames.

Reset animation to default values, clearing temporary frames, timers, current frames. Does NOT clear the defined animation loop, only the current 'status' of the animation.

void Actor::rotate double  dRot  )  [virtual]
 

Changes the actor's current rotation by dRot degrees.

Adjusts the actor's rotation by the given number of degrees.

Parameters:
dRot the number of degrees to adjust by. After function execution, your rotation will be (rotation + dRot)

void Actor::rotateFacing float  tx,
float  ty
[virtual]
 

Forces the actor to instantly turn towards a given (x,y) in worldspace.

Automatically set the actor's rotation to point at a given world space location. Uses angleTowards.

Parameters:
tx The x-coordinate of the world location to point toward
ty The y-coordinate of the world location to point toward

bool Actor::rotateTowards double  maxAngle,
double  goal
[virtual]
 

Make the actor face a certain angle "over time". Very useful for smooth, human-like turning.

Gradually rotate towards an angle. Call this over time to have a "smooth" turning motion towards things, like in Freezer and Glow.

Parameters:
maxAngle The maximum amount we can rotate this call
goal The final angle we want to be at
Returns:
True if the angle is reached, false otherwise.
rotate the target actor towards a "goal" angle, useful for gradually turning towards things

double Actor::rotationOutOf360  )  [protected]
 

Returns the actor's current rotation out of 360 (in degrees).

Uses angleOutOf360 to convert the actor's rotation to [0,360).

Returns:
The actor's rotation in degrees, normalized.

void Actor::setAnimation int  nStart,
int  nFrames,
float  nDelay
 

Allows you to override animation values permanently. This will not affect any temporary frames currently active.

Reset the animation loop's properties. Does not reset current animation values, so you should call reset() after using this function.

Parameters:
nStart the first frame to use in the animation loop.
nFrames The number of sequential frames to use in the animation loop.
nDelay The delay (in seconds) between frame switches.

void Actor::setHeight float  nh  ) 
 

Sets actor height in world units, affecting collision and rendering.

Set the actor's rendering and collision height, in world units. Silently fails if nh < 0

Parameters:
nh The new height of the actor, in world units.

void Actor::setRotation double  rot  )  [virtual]
 

Instantly sets the actor's rotation to a given angle in degrees.

Set the actor rotation in degrees.

Parameters:
rot The new rotation, in degrees. 0 is facing east, 90 north

void Actor::setWidth float  nw  ) 
 

Sets actor width in world units, affecting collision and rendering.

Set the actor's rendering and collision width, in world units. Silently fails if nw < 0

Parameters:
nw The new width of the actor, in world units.

void Actor::setX float  nx  ) 
 

Set the actor's X (horizontal, east-west) coordinate in world units.

Set the actor X coordinate in the world.

Parameters:
nx The new X coordinate in world space.

void Actor::setXYWH float  nx,
float  ny,
float  nw,
float  nh
 

Sets actor (X,Y) position and dimensions at the same time.

Set the location and proportions at once.

Parameters:
nx The new X coordinate, in world space.
ny The new Y coordinate, in world space.
nw The width of the actor, in world space.
nh The height of the actor, in world space.

void Actor::setY float  ny  ) 
 

Sets the actor's Y (vertical, north-south) coordinate in world units.

Set the actor Y coordinate in the world.

Parameters:
ny The new Y coordinate in world space.

void Actor::temporaryFrame int  frame  )  [virtual]
 

Allows you to temporarily override standard animation, for a single frame. Resets the animation timer.

Interrupt animation temporarily, reset the frame timer, and substitute a frame. Useful for "momentary" actions like firing a gun or taking a hit. Once the timer "ticks over" to the next frame, this frame will be reset and the regular animation loop will continue as normal.

Parameters:
frame The new frame ID to use for the next frame interval.

void Actor::updateAnimation float  delta  ) 
 

Updates the animation timer, incrementing frames as necessary. Delta is in seconds.

Increments frame timer and automatically clears frame timer and increments frame in animation as necessary. Also loops automatically.

Parameters:
delta The number of seconds since the last animation update.


The documentation for this class was generated from the following files:
Generated on Sun Jan 14 16:49:12 2007 for Propane Injector by  doxygen 1.4.6