org.deken.game.movement
Class FourKeyMovement

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

public class FourKeyMovement
extends BaseMovement
implements KeyMovement

Title: Key Movement

Description: Animates a character based on key movements.

Copyright: Copyright (c) 2006

Version:
1.0
Author:
Gary Deken

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
FourKeyMovement()
          KeyMovement
FourKeyMovement(int upKeyID, int downKeyID, int rightKeyID, int leftKeyID)
          Creates a FourKeyMovement with the key IDs for the four cardinal directions.
 
Method Summary
 void addInputAction(InputAction inputAction)
          add an InputAction for monitoring.
 void collideHorizontal()
          collideHorizontal Adjust the horizontal (x axis) movement to a collision.
 void collideLayer()
          collideLayer Adjust the layer (z axis) movement to a collision.
 void collideVertical()
          collideVertical Adjust the vertical (y axis) movement to a collision.
 FourKeyMovement copy(Actor actor)
          Copies this movement
 int[] getInputActionIds()
          Gets the Key IDs.
 KeyDirectionAction[] getKeyDirectionActions()
          This methods returns the list of KeyDirectionActions for this KeyMovement.
 java.lang.String getName()
           
 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 method is called when any event occurs.
 void setKeyDirectionAction(int index, int keyID, float direction)
          If the index is 0 or 3, 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, 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
 

Field Detail

keyDirectionActions

protected KeyDirectionAction[] keyDirectionActions

keyIDs

protected int[] keyIDs

currentXMovement

protected double currentXMovement

currentYMovement

protected double currentYMovement

speed

protected double speed
Constructor Detail

FourKeyMovement

public FourKeyMovement()
KeyMovement


FourKeyMovement

public FourKeyMovement(int upKeyID,
                       int downKeyID,
                       int rightKeyID,
                       int leftKeyID)
Creates a FourKeyMovement with the key IDs for the four cardinal directions.

Parameters:
upKeyID -
downKeyID -
rightKeyID -
leftKeyID -
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()
collideHorizontal Adjust the horizontal (x axis) movement to a collision.

Specified by:
collideHorizontal in interface Movement

collideVertical

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

Specified by:
collideVertical in interface Movement

collideLayer

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

Specified by:
collideLayer in interface Movement

copy

public FourKeyMovement copy(Actor actor)
Copies this movement

Specified by:
copy in interface Movement
Returns:
Movement

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[]

getName

public java.lang.String getName()
Specified by:
getName in interface Updateable
Overrides:
getName in class BaseMovement
Returns:

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)
Description copied from interface: InputListener
This method is called when any event occurs.

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 3, 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

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