The Game Engine  1
Player Class Reference

Interface for player-world interaction. More...

#include <Player.h>

+ Collaboration diagram for Player:

Public Types

enum  InputAction {
  Accept, Deny, OpenMenu, Esc,
  Move, MoveUp, MoveDown, MoveLeft,
  MoveRight, Cursor, CursorUp, CursorDown,
  CursorLeft, CursorRight, Action, HotKey1,
  HotKey2, HotKey3, HotKey4, HotKey5,
  HotKey6, HotKey7, HotKey8, HotKey9,
  HotKey10, HotKey11, HotKey12, LBump,
  RBump, LTrigger, RTrigger
}
 This should be a list of all things that would usually appear in a game as settable to some hotkey. More...
 

Public Member Functions

 Player (string filename)
 
 Player (map< InputAction, vector< SDLKey >> keyMaps)
 
 Player (map< InputAction, vector< JoyStick >> joyMaps, map< InputAction, vector< JoyButton >> buttonMaps, int moveJoy=0)
 
void Control (WorldObject *wo)
 Adds an object to list of controlled objects. More...
 
void RemoveControl (WorldObject *wo)
 Removes Player control over a given Object. More...
 
void RemoveControl (string woName)
 Removes Player control over a given Object with given name. More...
 
WorldObjectgetObject (string name)
 Get a pointer to the WorldObject with the specified name. More...
 
WorldObjectgetObject (unsigned int index)
 Get a pointer to the WorldObject in the specified position of the players WorldObject vector. More...
 
vector< WorldObject * > getObjects ()
 Get a vector of all WorldObject pointers belonging to the player. More...
 
vector< WorldObject * > getObjects (string name, int count=-1)
 Get a vector of WorldObject pointers with given name. More...
 
Point2D getAveragePosition ()
 Calculate the average position of the player's WorldObjects. More...
 
Point2D getAveragePosition (string name)
 Get the position of the player's WorldObject with the specified name. More...
 
Point2D getAveragePosition (vector< int > indices)
 Calculate the position of the player using the WorldObjects specified by the vector of indices. More...
 
Point2D getAveragePosition (vector< string > names)
 Calculate the position of the player using the WorldObjects with the names included in the vector. More...
 
void setPosition (double x, double y)
 Set the position of all objects unde the control of the Player using the average position of the objects. More...
 
void setPosition (Point2D pos)
 Set the position of all objects unde the control of the Player using the average position of the objects. More...
 
void move (double dx, double dy)
 Move by given relative amount (doing collision) More...
 
void move (Point2D direction)
 Moves the Player relative to the current pos (doing collision). More...
 
void moveTowards (Point2D point)
 Moves the Player towards the given point (Path finding). More...
 
void setTransparency (float f)
 Sets the transparency of the player by setting the transparency of all of the player's WorldObjects. More...
 
void changeTransparency (float df)
 Sets the relative transparency of the player by setting the transparency of all of the player's WorldObjects. More...
 
void addKeyDownCallback (void(*fn)(SDLKey, SDLMod))
 Add a keyboard button down callback. More...
 
void removeKeyDownCallback (void(*fn)(SDLKey, SDLMod))
 remove a keyboard button down callback More...
 
void addKeyUpCallback (void(*fn)(SDLKey, SDLMod))
 Add a keyboard button down callback. More...
 
void removeKeyUpCallback (void(*fn)(SDLKey, SDLMod))
 remove a keyboard button down callback More...
 
void addMouseDownCallback (void(*fn)(Uint8, Input::MouseState))
 Add a keyboard button down callback. More...
 
void removeMouseDownCallback (void(*fn)(Uint8, Input::MouseState))
 remove a keyboard button down callback More...
 
void addMouseUpCallback (void(*fn)(Uint8, Input::MouseState))
 Add a keyboard button down callback. More...
 
void removeMouseUpCallback (void(*fn)(Uint8, Input::MouseState))
 remove a keyboard button down callback More...
 
void addMouseMoveCallback (void(*fn)(Input::MouseState))
 Add a keyboard button down callback. More...
 
void removeMouseMoveCallback (void(*fn)(Input::MouseState))
 remove a keyboard button down callback More...
 
void addJoyButtonDownCallback (void(*fn)(Uint8, JoyButton))
 Add a keyboard button down callback. More...
 
void removeJoyButtonDownCallback (void(*fn)(Uint8, JoyButton))
 remove a keyboard button down callback More...
 
void addJoyButtonUpCallback (void(*fn)(Uint8, JoyButton))
 Add a keyboard button down callback. More...
 
void removeJoyButtonUpCallback (void(*fn)(Uint8, JoyButton))
 remove a keyboard button down callback More...
 
void addJoyMoveCallback (void(*fn)(Uint8, JoyStick, Point2D))
 Add a keyboard button down callback. More...
 
void removeJoyMoveCallback (void(*fn)(Uint8, JoyStick, Point2D))
 remove a keyboard button down callback More...
 
Point2D getMovement (InputAction act=Move)
 Obtain the movement Value from this input. More...
 
bool pressed (InputAction act)
 Whether a key is pressed on this input. More...
 
bool triggered (InputAction act, int ms=-1)
 Whether a key is triggered. More...
 
bool doubleTapped (InputAction act, int ms=-1)
 Whether a key is double tapped. More...
 

Static Public Member Functions

static bool getAllPressed (InputAction act)
 Check all inputs for values of act being down. More...
 
static bool getAllTriggered (InputAction act, int ms=-1)
 Check all inputs for values for act being triggered (down then up) More...
 
static Point2D getAllMovement (InputAction act=Move)
 Check all inputs for values of movement. More...
 

Protected Attributes

vector< WorldObject * > mObjects
 The list of objects we control. More...
 
InputmInput
 Input device we are getting input from. More...
 
map< InputAction, vector
< SDLKey > > 
mKeyMaps
 map from InputAction to actual keyboard input More...
 
map< InputAction, vector
< JoyButton > > 
mJoyButtonMaps
 map from InputAction to joystick buttons More...
 
map< InputAction, vector
< JoyStick > > 
mJoyStickMaps
 map from InputAction to joystick buttons More...
 
bool useJoystick
 Whether or not to use the Joystick for input. More...
 

Detailed Description

Interface for player-world interaction.

This class is tasked with the following:

  • keeping track of all objects under its control
  • keeping track of and managing input devices
  • providing an interface to update objects under its control

Definition at line 18 of file Player.h.

Member Enumeration Documentation

This should be a list of all things that would usually appear in a game as settable to some hotkey.

Todo:
this needs to be loaded/generated from a config file.
Enumerator
Accept 
Deny 
OpenMenu 
Esc 
Move 
MoveUp 
MoveDown 
MoveLeft 
MoveRight 
Cursor 
CursorUp 
CursorDown 
CursorLeft 
CursorRight 
Action 
HotKey1 
HotKey2 
HotKey3 
HotKey4 
HotKey5 
HotKey6 
HotKey7 
HotKey8 
HotKey9 
HotKey10 
HotKey11 
HotKey12 
LBump 
RBump 
LTrigger 
RTrigger 

Definition at line 27 of file Player.h.

Constructor & Destructor Documentation

Player::Player ( string  filename)
Todo:
LOAD FROM FILE!!!!
Todo:
fix up the initialization

Definition at line 4 of file Player.cpp.

+ Here is the call graph for this function:

Player::Player ( map< InputAction, vector< SDLKey >>  keyMaps)

Definition at line 124 of file Player.cpp.

Player::Player ( map< InputAction, vector< JoyStick >>  joyMaps,
map< InputAction, vector< JoyButton >>  buttonMaps,
int  moveJoy = 0 
)

Definition at line 129 of file Player.cpp.

Member Function Documentation

void Player::addJoyButtonDownCallback ( void(*)(Uint8, JoyButton fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addJoyButtonUpCallback ( void(*)(Uint8, JoyButton fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addJoyMoveCallback ( void(*)(Uint8, JoyStick, Point2D fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addKeyDownCallback ( void(*)(SDLKey, SDLMod)  fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addKeyUpCallback ( void(*)(SDLKey, SDLMod)  fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addMouseDownCallback ( void(*)(Uint8, Input::MouseState fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addMouseMoveCallback ( void(*)(Input::MouseState fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::addMouseUpCallback ( void(*)(Uint8, Input::MouseState fn)

Add a keyboard button down callback.

Parameters
fnThe function to add
void Player::changeTransparency ( float  df)

Sets the relative transparency of the player by setting the transparency of all of the player's WorldObjects.

Parameters
dfThe amount to change the Player's transparency

Definition at line 286 of file Player.cpp.

void Player::Control ( WorldObject wo)

Adds an object to list of controlled objects.

Parameters
woWorld object to put under player's control

Definition at line 135 of file Player.cpp.

+ Here is the caller graph for this function:

bool Player::doubleTapped ( Player::InputAction  act,
int  ms = -1 
)

Whether a key is double tapped.

Parameters
actThe action to determine
msThis value is an optional value that checks against the given ms instead of TRIGGERTIME (this value cannot be larger than 2^31)
Returns
whether the button has been pressed within TRIGGERTIME (this value cannot be larger than 2^31) ticks
Todo:
define a trigger time
Todo:
make this check if shift and ctrl are down instead of triggered and triggered for the rest

Definition at line 346 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point2D Player::getAllMovement ( Player::InputAction  act = Move)
static

Check all inputs for values of movement.

  • For keyboard this would generate a vector based on movement keys
  • For joysticks the vetor will be the raw vector of the up/down left/right axes

Definition at line 317 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Player::getAllPressed ( Player::InputAction  act)
static

Check all inputs for values of act being down.

Parameters
actThe action to be pressed

Definition at line 295 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Player::getAllTriggered ( Player::InputAction  act,
int  ms = -1 
)
static

Check all inputs for values for act being triggered (down then up)

Parameters
msThis value is an optional value that checks against the given ms instead of TRIGGERTIME
actAction to be triggered

Definition at line 306 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point2D Player::getAveragePosition ( )

Calculate the average position of the player's WorldObjects.

Returns
The average position of all WorldOjects under Player's control

Definition at line 190 of file Player.cpp.

+ Here is the caller graph for this function:

Point2D Player::getAveragePosition ( string  name)

Get the position of the player's WorldObject with the specified name.

Parameters
nameName of the WorldObject that the position will be defined by.
Returns
Returns the position of the first WorldObject under the Player's contorl with given name

Definition at line 201 of file Player.cpp.

+ Here is the call graph for this function:

Point2D Player::getAveragePosition ( vector< int >  indices)

Calculate the position of the player using the WorldObjects specified by the vector of indices.

Parameters
indicesList of WorldObject positions in the players vector of WorldObjects that specifies which WorldObjects to include when calculating the player position.
Returns
The average position of the Player controlled objects at the given indices.

Definition at line 208 of file Player.cpp.

Point2D Player::getAveragePosition ( vector< string >  names)

Calculate the position of the player using the WorldObjects with the names included in the vector.

Parameters
namesList of WorldObject names for objects that will be used when calculating the player position.
Returns
The average position of Player controlled objects with the given names

Definition at line 219 of file Player.cpp.

+ Here is the call graph for this function:

Point2D Player::getMovement ( Player::InputAction  act = Move)

Obtain the movement Value from this input.

Parameters
actThe action/Joystick to obtain movement data for
Returns
  • For keyboard this would generate a vector based on movement keys
  • For joysticks the vetor will be the raw vector of the up/down left/right axes

Definition at line 365 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

WorldObject * Player::getObject ( string  name)

Get a pointer to the WorldObject with the specified name.

Parameters
nameName of the desired WorldObject.
Returns
The first WorldObject with the given name

Definition at line 155 of file Player.cpp.

+ Here is the caller graph for this function:

WorldObject * Player::getObject ( unsigned int  index)

Get a pointer to the WorldObject in the specified position of the players WorldObject vector.

Parameters
indexPosition of the desired WorldObject.
Returns
The WorldObject at the given index

Definition at line 166 of file Player.cpp.

vector< WorldObject * > Player::getObjects ( )

Get a vector of all WorldObject pointers belonging to the player.

Returns
All WorldObjects under control by this player

Definition at line 171 of file Player.cpp.

+ Here is the caller graph for this function:

vector< WorldObject * > Player::getObjects ( string  name,
int  count = -1 
)

Get a vector of WorldObject pointers with given name.

If count is specified, then it will return at most that many pointers.

Parameters
nameName of the WorldObject desired by the user.
countMaximum number of pointers to retrieve.
Returns
Returns the first count number of objects under the Player's control

Definition at line 176 of file Player.cpp.

void Player::move ( double  dx,
double  dy 
)

Move by given relative amount (doing collision)

Parameters
dxAmount to move x
dyAmount to move y

Definition at line 257 of file Player.cpp.

+ Here is the caller graph for this function:

void Player::move ( Point2D  direction)

Moves the Player relative to the current pos (doing collision).

Parameters
directionDirection to move the Player

Definition at line 264 of file Player.cpp.

void Player::moveTowards ( Point2D  point)

Moves the Player towards the given point (Path finding).

Parameters
pointPoint to move the Player towards.
Todo:
Implement with AI

Definition at line 271 of file Player.cpp.

bool Player::pressed ( InputAction  act)

Whether a key is pressed on this input.

Parameters
actThe action to determine
Returns
whether the button is currently down

Definition at line 387 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Player::RemoveControl ( WorldObject wo)

Removes Player control over a given Object.

Parameters
woObject to stop controlling

Definition at line 139 of file Player.cpp.

void Player::RemoveControl ( string  woName)

Removes Player control over a given Object with given name.

Parameters
woNameObject to stop controlling

Definition at line 147 of file Player.cpp.

void Player::removeJoyButtonDownCallback ( void(*)(Uint8, JoyButton fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeJoyButtonUpCallback ( void(*)(Uint8, JoyButton fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeJoyMoveCallback ( void(*)(Uint8, JoyStick, Point2D fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeKeyDownCallback ( void(*)(SDLKey, SDLMod)  fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeKeyUpCallback ( void(*)(SDLKey, SDLMod)  fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeMouseDownCallback ( void(*)(Uint8, Input::MouseState fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeMouseMoveCallback ( void(*)(Input::MouseState fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::removeMouseUpCallback ( void(*)(Uint8, Input::MouseState fn)

remove a keyboard button down callback

Parameters
fnThe function to add
void Player::setPosition ( double  x,
double  y 
)

Set the position of all objects unde the control of the Player using the average position of the objects.

Parameters
xNew x position of the centroid of the player.
yNew y position of the centroid of the player.

Definition at line 235 of file Player.cpp.

+ Here is the call graph for this function:

void Player::setPosition ( Point2D  pos)

Set the position of all objects unde the control of the Player using the average position of the objects.

Parameters
posNew position for the centroid of the player.

Definition at line 246 of file Player.cpp.

+ Here is the call graph for this function:

void Player::setTransparency ( float  f)

Sets the transparency of the player by setting the transparency of all of the player's WorldObjects.

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

Definition at line 279 of file Player.cpp.

bool Player::triggered ( Player::InputAction  act,
int  ms = -1 
)

Whether a key is triggered.

Parameters
actThe action to determine
msThis value is an optional value that checks against the given ms instead of TRIGGERTIME (this value cannot be larger than 2^31)
Returns
whether the button has been pressed within TRIGGERTIME (this value cannot be larger than 2^31) ticks
Todo:
define a trigger time

Definition at line 328 of file Player.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Input* Player::mInput
protected

Input device we are getting input from.

Definition at line 348 of file Player.h.

map<InputAction, vector<JoyButton> > Player::mJoyButtonMaps
protected

map from InputAction to joystick buttons

Definition at line 354 of file Player.h.

map<InputAction, vector<JoyStick> > Player::mJoyStickMaps
protected

map from InputAction to joystick buttons

Definition at line 357 of file Player.h.

map<InputAction, vector<SDLKey> > Player::mKeyMaps
protected

map from InputAction to actual keyboard input

Definition at line 351 of file Player.h.

vector<WorldObject*> Player::mObjects
protected

The list of objects we control.

Definition at line 345 of file Player.h.

bool Player::useJoystick
protected

Whether or not to use the Joystick for input.

Definition at line 360 of file Player.h.


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