Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. public class KeyBinding implements KeyListener
  2. {
  3.   public static int KEY_JUMP = KeyEvent.VK_Y;
  4.   public static int KEY_ACTION = KeyEvent.VK_X;
  5.   public static int KEY_INVENTORY = KeyEvent.VK_A;
  6.   public static int KEY_LEFT = KeyEvent.VK_LEFT;
  7.   public static int KEY_RIGHT = KeyEvent.VK_RIGHT;
  8.   public static int KEY_UP = KeyEvent.VK_UP;
  9.   public static int KEY_DOWN = KeyEvent.VK_DOWN;
  10.   public static int KEY_RUN = KeyEvent.VK_C;
  11.  
  12.   public static boolean jumpDown;
  13.   public static boolean actionDown;
  14.   public static boolean inventoryDown;
  15.   public static boolean leftDown;
  16.   public static boolean rightDown;
  17.   public static boolean upDown;
  18.   public static boolean downDown;
  19.   public static boolean runDown;
  20.  
  21.   @Override
  22.   public void keyTyped(KeyEvent e)
  23.   {
  24.    
  25.   }
  26.  
  27.   @Override
  28.   public void keyPressed(KeyEvent e)
  29.   {
  30.     if(e.getKeyCode() == KEY_JUMP)
  31.     {
  32.       jumpDown = true;
  33.     }
  34.     if(e.getKeyCode() == KEY_ACTION)
  35.     {
  36.       actionDown = true;
  37.     }
  38.     if(e.getKeyCode() == KEY_INVENTORY)
  39.     {
  40.       inventoryDown = true;
  41.     }
  42.     if(e.getKeyCode() == KEY_LEFT)
  43.     {
  44.       leftDown = true;
  45.     }
  46.     if(e.getKeyCode() == KEY_RIGHT)
  47.     {
  48.       rightDown = true;
  49.     }
  50.     if(e.getKeyCode() == KEY_UP)
  51.     {
  52.       upDown = true;
  53.     }
  54.     if(e.getKeyCode() == KEY_DOWN)
  55.     {
  56.       downDown = true;
  57.     }
  58.     if(e.getKeyCode() == KEY_RUN)
  59.     {
  60.       runDown = true;
  61.     }
  62.   }
  63.  
  64.   @Override
  65.   public void keyReleased(KeyEvent e)
  66.   {
  67.     if(e.getKeyCode() == KEY_JUMP)
  68.     {
  69.       jumpDown = false;
  70.     }
  71.     if(e.getKeyCode() == KEY_ACTION)
  72.     {
  73.       actionDown = false;
  74.     }
  75.     if(e.getKeyCode() == KEY_INVENTORY)
  76.     {
  77.       inventoryDown = false;
  78.     }
  79.     if(e.getKeyCode() == KEY_LEFT)
  80.     {
  81.       leftDown = false;
  82.     }
  83.     if(e.getKeyCode() == KEY_RIGHT)
  84.     {
  85.       rightDown = false;
  86.     }
  87.     if(e.getKeyCode() == KEY_UP)
  88.     {
  89.       upDown = false;
  90.     }
  91.     if(e.getKeyCode() == KEY_DOWN)
  92.     {
  93.       downDown = false;
  94.     }
  95.     if(e.getKeyCode() == KEY_RUN)
  96.     {
  97.       runDown = false;
  98.     }
  99.   }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement