SHARE
TWEET

Untitled

a guest Sep 6th, 2014 5 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package project.x;
  2.  
  3. import java.awt.event.KeyEvent;
  4. import java.awt.event.KeyListener;
  5. import java.io.IOException;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8. import javax.swing.JFrame;
  9.  
  10. public class Keyboard implements KeyListener {
  11.        
  12.     public void keyTyped(KeyEvent e) {
  13.    
  14.     }
  15.  
  16.     public void keyPressed(KeyEvent e) {
  17.         if (e.getKeyCode() == KeyEvent.VK_UP) {
  18.             Display.getPlayer().up = true;
  19.             Display.playerMoved = true;
  20.             Player.playerDirection = 3;
  21.         }
  22.        
  23.         if (e.getKeyCode() == KeyEvent.VK_DOWN) {
  24.             Display.getPlayer().down = true;
  25.             Display.playerMoved = true;
  26.             Player.playerDirection = 0;
  27.         }
  28.        
  29.         if (e.getKeyCode() == KeyEvent.VK_LEFT) {
  30.             Display.getPlayer().left = true;
  31.             Display.playerMoved = true;
  32.             Player.playerDirection = 1;
  33.         }
  34.        
  35.         if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
  36.             Display.getPlayer().right = true;
  37.             Display.playerMoved = true;
  38.             Player.playerDirection = 2;
  39.         }
  40.         if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
  41.             try {
  42.                 // Save Level & Player Data here, Before returning to the Launcher
  43.                 // Perhaps ask for confirmation?
  44.                 JFrame killFrame = Display.getJFrame();
  45.                 killFrame.dispose();
  46.                 Display.stopThread();
  47.                 new LauncherGUI(0);
  48.             } catch (IOException ex) {
  49.                 Logger.getLogger(Keyboard.class.getName()).log(Level.SEVERE, null, ex);
  50.             } catch (InterruptedException ex) {
  51.                 Logger.getLogger(Keyboard.class.getName()).log(Level.SEVERE, null, ex);
  52.             }
  53.         }
  54.     }
  55.  
  56.     public void keyReleased(KeyEvent e) {
  57.         if (e.getKeyCode() == KeyEvent.VK_UP) {
  58.             Display.getPlayer().up = false;
  59.             Display.playerMoved = false;
  60.             Player.playerDirection = 3;
  61.         }
  62.        
  63.         if (e.getKeyCode() == KeyEvent.VK_DOWN) {
  64.             Display.getPlayer().down = false;
  65.             Display.playerMoved = false;
  66.             Player.playerDirection = 0;
  67.         }
  68.        
  69.         if (e.getKeyCode() == KeyEvent.VK_LEFT) {
  70.             Display.getPlayer().left = false;
  71.             Display.playerMoved = false;
  72.             Player.playerDirection = 1;
  73.         }
  74.        
  75.         if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
  76.             Display.getPlayer().right = false;
  77.             Display.playerMoved = false;
  78.             Player.playerDirection = 2;
  79.         }
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top