C# Class SunsetHigh.KeyboardManager

Static class that has three purposes: 1) To easily tell if a key is held down or has been just pressed, 2) To handle complex keyboard input for the game with simple method calls, 3) To store custom key controls for the game.
Mostrar archivo Open project: ErraticUnicorn/MOSH

Public Methods

Method Description
changeKeyControl ( KeyInputType inputType, Keys key ) : void

Change the key input needed to trigger a given game function; used for customizing key controls

getKeyControl ( KeyInputType inputType ) : Keys

Returns the current Key mapped to this KeyInputType

getKeyControls ( ) : Keys[]

Used for saving purposes only

getNewKeyPressed ( ) : Keys

Returns one key that has just been pressed (assuming it's the only key pressed)

handleCharacterMovement ( Character character, float elapsed ) : void

Ts Character movement in 8 directions; call this method in the Game's update cycle (AFTER calling KeyboardManager.update())

handleInGameMenu ( ) : void
handleInteractions ( Hero hero, List targets ) : void

Handles the Hero talking with Characters. Will be expanded later to "interact" with scenery as well.

handlePickpocketing ( Hero hero, List targets ) : void

Handles the Hero's pickpocketing ability; call this method in the Game's update cycle (AFTER calling KeyboardManager.update())

handleShooting ( Hero hero ) : void

Handles Hero's "weapon" ability; call this method in the Game's update cycle (AFTER calling KeyboardManager.update())

handleSimpleScreen ( AbstractScreen sender ) : void
isKeyDown ( Keys key ) : bool

Checks if the given key is currently down (pressed)

isKeyPressed ( Keys key ) : bool

Checks if the given key has just been pressed (i.e. it is down now and was not pressed in the previous update)

isKeyUnpressed ( Keys key ) : bool

Checks if the given key has just been released (i.e. it is up now and was pressed in the previous update)

isKeyUp ( Keys key ) : bool

Checks if the given key is currently up (not pressed)

isNewKeyPressed ( ) : bool

Checks if any new key has just been pressed (and was not down previously)

keyControlExists ( Keys key, KeyInputType exclude ) : bool

A check for whether the given key is already registered with a certain type of input. Called when customizing key controls

loadDefaultKeys ( ) : void

Used for loading the default key controls when starting a game (or resetting controls)

loadKeyControls ( Keys loadableKeys ) : void

Used for loading in custom key controls when restoring a saved game

update ( ) : void

Updates the keyboard input; call this method in the Game's update cycle

Private Methods

Method Description
nullCheck ( ) : void

Method Details

changeKeyControl() public static method

Change the key input needed to trigger a given game function; used for customizing key controls
public static changeKeyControl ( KeyInputType inputType, Keys key ) : void
inputType KeyInputType The game function
key Keys The new key to press
return void

getKeyControl() public static method

Returns the current Key mapped to this KeyInputType
public static getKeyControl ( KeyInputType inputType ) : Keys
inputType KeyInputType
return Keys

getKeyControls() public static method

Used for saving purposes only
public static getKeyControls ( ) : Keys[]
return Keys[]

getNewKeyPressed() public static method

Returns one key that has just been pressed (assuming it's the only key pressed)
public static getNewKeyPressed ( ) : Keys
return Keys

handleCharacterMovement() public static method

Ts Character movement in 8 directions; call this method in the Game's update cycle (AFTER calling KeyboardManager.update())
public static handleCharacterMovement ( Character character, float elapsed ) : void
character Character The character to control (presumably main character)
elapsed float The time that elapsed since the last update
return void

handleInGameMenu() public static method

public static handleInGameMenu ( ) : void
return void

handleInteractions() public static method

Handles the Hero talking with Characters. Will be expanded later to "interact" with scenery as well.
public static handleInteractions ( Hero hero, List targets ) : void
hero Hero The main character
targets List List of interactables in the scene
return void

handlePickpocketing() public static method

Handles the Hero's pickpocketing ability; call this method in the Game's update cycle (AFTER calling KeyboardManager.update())
public static handlePickpocketing ( Hero hero, List targets ) : void
hero Hero The main character
targets List List of characters in the scene; one that is in range is chosen randomly
return void

handleShooting() public static method

Handles Hero's "weapon" ability; call this method in the Game's update cycle (AFTER calling KeyboardManager.update())
public static handleShooting ( Hero hero ) : void
hero Hero
return void

handleSimpleScreen() public static method

public static handleSimpleScreen ( AbstractScreen sender ) : void
sender AbstractScreen
return void

isKeyDown() public static method

Checks if the given key is currently down (pressed)
public static isKeyDown ( Keys key ) : bool
key Keys The key to check for
return bool

isKeyPressed() public static method

Checks if the given key has just been pressed (i.e. it is down now and was not pressed in the previous update)
public static isKeyPressed ( Keys key ) : bool
key Keys The key to check for
return bool

isKeyUnpressed() public static method

Checks if the given key has just been released (i.e. it is up now and was pressed in the previous update)
public static isKeyUnpressed ( Keys key ) : bool
key Keys The key to check for
return bool

isKeyUp() public static method

Checks if the given key is currently up (not pressed)
public static isKeyUp ( Keys key ) : bool
key Keys The key to check for
return bool

isNewKeyPressed() public static method

Checks if any new key has just been pressed (and was not down previously)
public static isNewKeyPressed ( ) : bool
return bool

keyControlExists() public static method

A check for whether the given key is already registered with a certain type of input. Called when customizing key controls
public static keyControlExists ( Keys key, KeyInputType exclude ) : bool
key Keys The possible key to shift the input type to
exclude KeyInputType Input type to exclude (i.e. the input being considered)
return bool

loadDefaultKeys() public static method

Used for loading the default key controls when starting a game (or resetting controls)
public static loadDefaultKeys ( ) : void
return void

loadKeyControls() public static method

Used for loading in custom key controls when restoring a saved game
public static loadKeyControls ( Keys loadableKeys ) : void
loadableKeys Keys A Keys[] representation of the key controls
return void

update() public static method

Updates the keyboard input; call this method in the Game's update cycle
public static update ( ) : void
return void