com.brackeen.javagamebook.input
Class GameAction

java.lang.Object
  extended by com.brackeen.javagamebook.input.GameAction

public class GameAction
extends java.lang.Object

The GameAction class is an abstract to a user-initiated action, like jumping or moving. GameActions can be mapped to keys or the mouse with the InputManager.


Field Summary
private  int amount
           
private  int behavior
           
static int DETECT_INITAL_PRESS_ONLY
          Initial press behavior.
private  java.lang.String name
           
static int NORMAL
          Normal behavior.
private  int state
           
private static int STATE_PRESSED
           
private static int STATE_RELEASED
           
private static int STATE_WAITING_FOR_RELEASE
           
 
Constructor Summary
GameAction(java.lang.String name)
          Create a new GameAction with the NORMAL behavior.
GameAction(java.lang.String name, int behavior)
          Create a new GameAction with the specified behavior.
 
Method Summary
 int getAmount()
          For keys, this is the number of times the key was pressed since it was last checked.
 java.lang.String getName()
          Gets the name of this GameAction.
 boolean isPressed()
          Returns whether the key was pressed or not since last checked.
 void press()
          Signals that the key was pressed.
 void press(int amount)
          Signals that the key was pressed a specified number of times, or that the mouse move a spcified distance.
 void release()
          Signals that the key was released
 void reset()
          Resets this GameAction so that it appears like it hasn't been pressed.
 void tap()
          Taps this GameAction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL

public static final int NORMAL
Normal behavior. The isPressed() method returns true as long as the key is held down.

See Also:
Constant Field Values

DETECT_INITAL_PRESS_ONLY

public static final int DETECT_INITAL_PRESS_ONLY
Initial press behavior. The isPressed() method returns true only after the key is first pressed, and not again until the key is released and pressed again.

See Also:
Constant Field Values

STATE_RELEASED

private static final int STATE_RELEASED
See Also:
Constant Field Values

STATE_PRESSED

private static final int STATE_PRESSED
See Also:
Constant Field Values

STATE_WAITING_FOR_RELEASE

private static final int STATE_WAITING_FOR_RELEASE
See Also:
Constant Field Values

name

private java.lang.String name

behavior

private int behavior

amount

private int amount

state

private int state
Constructor Detail

GameAction

public GameAction(java.lang.String name)
Create a new GameAction with the NORMAL behavior.


GameAction

public GameAction(java.lang.String name,
                  int behavior)
Create a new GameAction with the specified behavior.

Method Detail

getName

public java.lang.String getName()
Gets the name of this GameAction.


reset

public void reset()
Resets this GameAction so that it appears like it hasn't been pressed.


tap

public void tap()
Taps this GameAction. Same as calling press() followed by release().


press

public void press()
Signals that the key was pressed.


press

public void press(int amount)
Signals that the key was pressed a specified number of times, or that the mouse move a spcified distance.


release

public void release()
Signals that the key was released


isPressed

public boolean isPressed()
Returns whether the key was pressed or not since last checked.


getAmount

public int getAmount()
For keys, this is the number of times the key was pressed since it was last checked. For mouse movement, this is the distance moved.