Rally X
ELEN3009 Project by Justin Wernick and David Schneider
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
KeyboardHandler Class Reference

Class for handling keyboard related game inputs from the player. More...

#include <KeyboardHandler.h>

List of all members.

Public Member Functions

 KeyboardHandler (Maze::Direction currentFacing)
 Creates a KeyboardHandler with a given initial state.
 KeyboardHandler (const KeyboardHandler &ref)
 Copy constructor that ensures that a copy of a KeyboardHandler will have its own event queue.
KeyboardHandleroperator= (const KeyboardHandler &rhs)
 Assignment operator that ensures that an assigned KeyboardHandler will have its own event queue.
 ~KeyboardHandler ()
 Cleans up the keyboard event queue.
Maze::Direction getFacing ()
 Gives the last direction that the player entered on the keyboard.
bool getSmokescreen ()
 Gives whether or not the key for creating a Smokescreen is currently pressed.

Private Member Functions

void updateFlags ()
 Processes all pending keyboard inputs, and updates flags as appropriate.

Private Attributes

AllegroKeyboardInit _keyboard
 Ensures that dependencies on the Allegro keyboard library are installed.
bool _up
 True if the up arrow key is depressed.
bool _down
 True if the down arrow key is depressed.
bool _left
 True if the left arrow key is depressed.
bool _right
 True if the right arrow key is depressed.
bool _smokescreen
 True if the smokescreen key is depressed.
Maze::Direction _previousFacing
 The direction that was returned on the last call of getFacing.
ALLEGRO_EVENT_QUEUE * _keyboardEvents
 Queue for all keyboard events.

Static Private Attributes

static const int UP_KEY = ALLEGRO_KEY_UP
 Key that must be pressed to turn up.
static const int DOWN_KEY = ALLEGRO_KEY_DOWN
 Key that must be pressed to turn down.
static const int LEFT_KEY = ALLEGRO_KEY_LEFT
 Key that must be pressed to turn left.
static const int RIGHT_KEY = ALLEGRO_KEY_RIGHT
 Key that must be pressed to turn right.
static const int SMOKESCREEN_KEY = ALLEGRO_KEY_SPACE
 Key that must be pressed to create a smokescreen.

Detailed Description

Class for handling keyboard related game inputs from the player.

Written with controlling a PlayerCar in mind. The handler keeps track of the last direction pushed and responds to requests from the PlayerCar for which direction it should face next, and whether the player is pressing the Smokescreen button.

Author:
Justin Wernick
David Schneider

Definition at line 19 of file KeyboardHandler.h.


Constructor & Destructor Documentation

KeyboardHandler::KeyboardHandler ( Maze::Direction  currentFacing)

Creates a KeyboardHandler with a given initial state.

Parameters:
[in]currentFacingThe initial value for the previous facing of the object being controlled.

Definition at line 3 of file KeyboardHandler.cpp.

KeyboardHandler::KeyboardHandler ( const KeyboardHandler ref)

Copy constructor that ensures that a copy of a KeyboardHandler will have its own event queue.

Definition at line 15 of file KeyboardHandler.cpp.

KeyboardHandler::~KeyboardHandler ( )

Cleans up the keyboard event queue.

Definition at line 44 of file KeyboardHandler.cpp.


Member Function Documentation

Maze::Direction KeyboardHandler::getFacing ( )

Gives the last direction that the player entered on the keyboard.

All pending keyboard events are processed, then a key out of those currently depressed is returned. The precendence for keys held down (up, down, left, then right) is arbitrary, since the player should not be holding down more than one arrow key at a time. If no keys are currently depressed, the value returned on the last call is returned again.

Returns:
The direction that the player has chosen through pressing arrow keys.

Definition at line 99 of file KeyboardHandler.cpp.

bool KeyboardHandler::getSmokescreen ( )

Gives whether or not the key for creating a Smokescreen is currently pressed.

Returns:
True if a Smokescreen should be created.

Definition at line 111 of file KeyboardHandler.cpp.

KeyboardHandler & KeyboardHandler::operator= ( const KeyboardHandler rhs)

Assignment operator that ensures that an assigned KeyboardHandler will have its own event queue.

Definition at line 27 of file KeyboardHandler.cpp.

void KeyboardHandler::updateFlags ( ) [private]

Processes all pending keyboard inputs, and updates flags as appropriate.

Definition at line 49 of file KeyboardHandler.cpp.


Member Data Documentation

bool KeyboardHandler::_down [private]

True if the down arrow key is depressed.

Definition at line 69 of file KeyboardHandler.h.

Ensures that dependencies on the Allegro keyboard library are installed.

Definition at line 61 of file KeyboardHandler.h.

ALLEGRO_EVENT_QUEUE* KeyboardHandler::_keyboardEvents [private]

Queue for all keyboard events.

Definition at line 74 of file KeyboardHandler.h.

bool KeyboardHandler::_left [private]

True if the left arrow key is depressed.

Definition at line 70 of file KeyboardHandler.h.

The direction that was returned on the last call of getFacing.

Definition at line 73 of file KeyboardHandler.h.

bool KeyboardHandler::_right [private]

True if the right arrow key is depressed.

Definition at line 71 of file KeyboardHandler.h.

True if the smokescreen key is depressed.

Definition at line 72 of file KeyboardHandler.h.

bool KeyboardHandler::_up [private]

True if the up arrow key is depressed.

Definition at line 68 of file KeyboardHandler.h.

const int KeyboardHandler::DOWN_KEY = ALLEGRO_KEY_DOWN [static, private]

Key that must be pressed to turn down.

Definition at line 77 of file KeyboardHandler.h.

const int KeyboardHandler::LEFT_KEY = ALLEGRO_KEY_LEFT [static, private]

Key that must be pressed to turn left.

Definition at line 78 of file KeyboardHandler.h.

const int KeyboardHandler::RIGHT_KEY = ALLEGRO_KEY_RIGHT [static, private]

Key that must be pressed to turn right.

Definition at line 79 of file KeyboardHandler.h.

const int KeyboardHandler::SMOKESCREEN_KEY = ALLEGRO_KEY_SPACE [static, private]

Key that must be pressed to create a smokescreen.

Definition at line 80 of file KeyboardHandler.h.

const int KeyboardHandler::UP_KEY = ALLEGRO_KEY_UP [static, private]

Key that must be pressed to turn up.

Definition at line 76 of file KeyboardHandler.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator