Class InputHandler

java.lang.Object
  |
  +--InputHandler
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener, javax.swing.event.MouseInputListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

class InputHandler
extends java.lang.Object
implements javax.swing.event.MouseInputListener, java.awt.event.KeyListener

InputHandler class for mouse and keyboard input from the user.


Field Summary
 java.util.Vector m_commands
           
 double maxpower
           
 double minpower
           
private  java.awt.Point mousePosition
           
private  PlayerCanvas p_canvas
           
private  double power
           
private  double powerScale
           
 boolean running
           
private  java.awt.Point user
           
 
Constructor Summary
InputHandler(PlayerCanvas p)
          InputHandler Constructor used for creating mouse and keyboard input handlers for the PlayerCanvas.
 
Method Summary
private  double getAngle(int x, int y)
          getAngle method, used for determining the angle at which the point (x,y) is from the centre view of the player.
private  double getDistance(int x, int y)
          getDistance method, used to obtain the distance to a point (x,y) from the player.
 void keyPressed(java.awt.event.KeyEvent e)
          keyPressed event, used for implementing default action when a key is pressed (example - space bar = kick
 void keyReleased(java.awt.event.KeyEvent e)
          keyReleased event - currently not implemented
 void keyTyped(java.awt.event.KeyEvent e)
          keyTyped event - currently not implemented
 void mouseClicked(java.awt.event.MouseEvent e)
          mouseClicked event, used for determining default actions when the mouse buttons are clicked - currently not implemented.
 void mouseDragged(java.awt.event.MouseEvent e)
          mouseDragged event, used for obtaining the canvas mouse position to where the mouse was dragged.
 void mouseEntered(java.awt.event.MouseEvent e)
          mouseEntered event - currently not implemented.
 void mouseExited(java.awt.event.MouseEvent e)
          mouseExited event - currently not implemented.
 void mouseMoved(java.awt.event.MouseEvent e)
          mouseMoved event, used for obtaining the canvas mouse position to where the mouse was moved.
 void mousePressed(java.awt.event.MouseEvent e)
          mousePressed event, used for determining the action to take, based on the mouse click.
 void mouseReleased(java.awt.event.MouseEvent e)
          mouseReleased event, used for determining the current mouse position on the canvas when the mouse button is released.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_commands

public java.util.Vector m_commands

p_canvas

private PlayerCanvas p_canvas

user

private java.awt.Point user

mousePosition

private java.awt.Point mousePosition

maxpower

public double maxpower

minpower

public double minpower

powerScale

private double powerScale

power

private double power

running

public boolean running
Constructor Detail

InputHandler

public InputHandler(PlayerCanvas p)
InputHandler Constructor used for creating mouse and keyboard input handlers for the PlayerCanvas.
Parameters:
p - PlayerCanvas to be used with input handling
Method Detail

getDistance

private double getDistance(int x,
                           int y)
getDistance method, used to obtain the distance to a point (x,y) from the player.
Parameters:
x - x-coordinate of the point
y - y-coordinate of the point
Returns:
Distance from the player to the point

getAngle

private double getAngle(int x,
                        int y)
getAngle method, used for determining the angle at which the point (x,y) is from the centre view of the player.
Parameters:
x - x-coordinate of the point
y - y-coordinate of the point
Returns:
Angle of the point from the centre view of the player.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
mousePressed event, used for determining the action to take, based on the mouse click. left click = dash with power relative to distance of mouse click from own player left hold = run (repeatedly dash every cycle at the same power) right click = turn with moment equal to the angle from straight ahead of own player
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - Mouse event which occurred.
Returns:
none

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased event, used for determining the current mouse position on the canvas when the mouse button is released.
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - Mouse event which occurred.
Returns:
none

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked event, used for determining default actions when the mouse buttons are clicked - currently not implemented.
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - Mouse event which occurred.
Returns:
none

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered event - currently not implemented.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - Mouse event which occurred.
Returns:
none

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
mouseExited event - currently not implemented.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - Mouse event which occurred.
Returns:
none

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved event, used for obtaining the canvas mouse position to where the mouse was moved.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - Mouse event which occurred.
Returns:
none

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged event, used for obtaining the canvas mouse position to where the mouse was dragged.
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - Mouse event which occurred.
Returns:
none

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
keyTyped event - currently not implemented
Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - Key event which occurred.
Returns:
none

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
keyPressed event, used for implementing default action when a key is pressed (example - space bar = kick
Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - Key event which occurred.
Returns:
none

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
keyReleased event - currently not implemented
Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - Key event which occurred.
Returns:
none