Advertisement
Guest User

Untitled

a guest
Sep 16th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import org.newdawn.slick.AppGameContainer;
  2. import org.newdawn.slick.BasicGame;
  3. import org.newdawn.slick.Color;
  4. import org.newdawn.slick.GameContainer;
  5. import org.newdawn.slick.Graphics;
  6. import org.newdawn.slick.Input;
  7. import org.newdawn.slick.SlickException;
  8. import org.newdawn.slick.util.Log;
  9.  
  10. public class BugTest extends BasicGame{
  11.     public final static Color down = Color.yellow;
  12.     public final static Color released = Color.white;
  13.     public final static String[] names = {"LSHIFT", "RSHIFT", "LCTRL", "SPACE", "X"};
  14.     public final static int[] codes = {Input.KEY_LSHIFT, Input.KEY_RSHIFT, Input.KEY_LCONTROL, Input.KEY_SPACE, Input.KEY_X};
  15.    
  16.    
  17.    
  18.     public static void main(String[] args) throws Exception
  19.     {
  20.         BugTest test = new BugTest();
  21.         AppGameContainer container = new AppGameContainer(test);
  22.         container.setShowFPS(false);
  23.         container.setDisplayMode(640, 480, false);
  24.         container.start();
  25.     }
  26.    
  27.     private boolean[] states = { false, false, false, false, false };
  28.    
  29.     public BugTest() {
  30.         super("Shift hang test");
  31.     }
  32.  
  33.     @Override
  34.     public void update(GameContainer container, int delta)
  35.             throws SlickException {
  36.         Input i = container.getInput();
  37.         for(int x = 0; x < codes.length; x++)
  38.         {
  39.             if(i.isKeyDown(codes[x]))
  40.             {
  41.                 Log.info(String.format("Down: %s", names[x]));
  42.                 states[x] = true;
  43.             }
  44.             else
  45.             {
  46.                 states[x] = false;
  47.             }
  48.         }
  49.     }
  50.  
  51.     @Override
  52.     public void render(GameContainer container, Graphics g) throws SlickException {
  53.         g.setColor(Color.white);
  54.         g.drawString("Keys registered for the test: ", 0, 0);
  55.         for(int index = 0; index < codes.length; index ++)
  56.         {
  57.             g.setColor(states[index] ? down : released);
  58.             g.drawString(String.format("%s: %s", names[index], states[index] ? "down" : "released"), 20, (index +1 )* 20);
  59.         }
  60.        
  61.     }
  62.  
  63.     @Override
  64.     public void init(GameContainer container) throws SlickException {}
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement