org.deken.game.movement
Class TwoKeyMovement

java.lang.Object
  extended by org.deken.game.movement.BaseMovement
      extended by org.deken.game.movement.TwoKeyMovement
All Implemented Interfaces:
InputListener, KeyMovement, Movement, Updateable

public class TwoKeyMovement
extends BaseMovement
implements KeyMovement


Field Summary
protected  double currentXMovement
           
protected  double currentYMovement
           
protected  KeyDirectionAction[] keyDirectionActions
           
protected  int[] keyIDs
           
protected  double speed
           
 
Fields inherited from class org.deken.game.movement.BaseMovement
gameVector, name
 
Constructor Summary
TwoKeyMovement()
          TwoKeyMovement
TwoKeyMovement(int rightKeyID, int leftKeyID)
           
 
Method Summary
 void addInputAction(InputAction inputAction)
          add an InputAction for monitoring.
 void collideHorizontal()
          Adjust the horizontal (x axis) movement to a collision.
 void collideLayer()
          Adjust the layer (z axis) movement to a collision.
 void collideVertical()
          Adjust the vertical (y axis) movement to a collision.
 TwoKeyMovement copy(Actor actor)
          Copies the movement.
 int[] getInputActionIds()
          Gets the Key IDs.
 KeyDirectionAction[] getKeyDirectionActions()
          This methods returns the list of KeyDirectionActions for this KeyMovement.
 double getSpeed()
           
 double getXUpdate()
          This returns the movement in the X direction since the last update.
 double getYUpdate()
          This returns the movement in the Y direction since the last update.
 void notifyListener(InputAction inputAction)
          This identifies which key was pressed or released.
 void setKeyDirectionAction(int index, int keyID, float direction)
          If the index is 0 or 1, set the KeyDirectionAction, with the given KeyID and Direction.
 void setSpeed(double speed)
          Sets the speed
 void update(long elapseTime)
          This identifies which key was pressed or released.
 
Methods inherited from class org.deken.game.movement.BaseMovement
baseCopy, getDirection, getGameVector, getName, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.deken.game.movement.Movement
getDirection, getGameVector
 
Methods inherited from interface org.deken.game.Updateable
getName
 

Field Detail

keyIDs

protected int[] keyIDs

keyDirectionActions

protected KeyDirectionAction[] keyDirectionActions

currentXMovement

protected double currentXMovement

currentYMovement

protected double currentYMovement

speed

protected double speed
Constructor Detail

TwoKeyMovement

public TwoKeyMovement()
TwoKeyMovement


TwoKeyMovement

public TwoKeyMovement(int rightKeyID,
                      int leftKeyID)
Parameters:
rightKeyID - KeyEvent
leftKeyID - KeyEvent
Method Detail

addInputAction

public void addInputAction(InputAction inputAction)
Description copied from interface: InputListener
add an InputAction for monitoring.

Specified by:
addInputAction in interface InputListener

collideHorizontal

public void collideHorizontal()
Adjust the horizontal (x axis) movement to a collision.

Specified by:
collideHorizontal in interface Movement

collideVertical

public void collideVertical()
Adjust the vertical (y axis) movement to a collision.

Specified by:
collideVertical in interface Movement

collideLayer

public void collideLayer()
Adjust the layer (z axis) movement to a collision.

Specified by:
collideLayer in interface Movement

copy

public TwoKeyMovement copy(Actor actor)
Description copied from interface: Movement
Copies the movement.

Specified by:
copy in interface Movement
Returns:
TwoKeyMovement

getInputActionIds

public int[] getInputActionIds()
Description copied from interface: InputListener
Gets the Key IDs. This is mainly used for wiring the object into the current GameMap Actions.

Specified by:
getInputActionIds in interface InputListener
Returns:
Array of InputActionIDs

getKeyDirectionActions

public KeyDirectionAction[] getKeyDirectionActions()
Description copied from interface: KeyMovement
This methods returns the list of KeyDirectionActions for this KeyMovement.

Specified by:
getKeyDirectionActions in interface KeyMovement
Returns:
KeyDirectionAction[]

getSpeed

public double getSpeed()
Returns:
double

getXUpdate

public double getXUpdate()
This returns the movement in the X direction since the last update.

Specified by:
getXUpdate in interface Movement
Returns:
double

getYUpdate

public double getYUpdate()
This returns the movement in the Y direction since the last update.

Specified by:
getYUpdate in interface Movement
Returns:
double

notifyListener

public void notifyListener(InputAction inputAction)
This identifies which key was pressed or released. if the action was pressed, it set the GameVector to that direction, and the speed to this Movement's speed. If the key was released, the GameVector's speed is set to 0.0.

Specified by:
notifyListener in interface InputListener
Parameters:
inputAction - InputAction

setKeyDirectionAction

public void setKeyDirectionAction(int index,
                                  int keyID,
                                  float direction)
If the index is 0 or 1, set the KeyDirectionAction, with the given KeyID and Direction.

Specified by:
setKeyDirectionAction in interface KeyMovement
Parameters:
index -
keyID -
direction -

setSpeed

public void setSpeed(double speed)
Description copied from interface: KeyMovement
Sets the speed

Specified by:
setSpeed in interface KeyMovement
Parameters:
speed - double

update

public void update(long elapseTime)
This identifies which key was pressed or released. if the action was pressed, it set the GameVector to that direction, and the speed to this Movement's speed. If the key was released, the GameVector's speed is set to 0.0.

Specified by:
update in interface Movement
Specified by:
update in interface Updateable
Parameters:
elapseTime - long