-
-
Save Elix-x/78c2f4ee9533eb07328e to your computer and use it in GitHub Desktop.
Solving strange null pointers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InputHandler { | |
public final KBOApi api; | |
private Map<Integer, Boolean> keyStatesMap = new HashMap<Integer, Boolean>(); | |
public InputHandler(KBOApi api) { | |
this.api = api; | |
} | |
public void tick(){ | |
for(int i = 0; i < Mouse.getButtonCount(); i++){ | |
setMouseKeyPressed(i, Mouse.isButtonDown(i)); | |
} | |
for(int i = 0; i < Keyboard.getKeyCount(); i++){ | |
setKeyboardKeyPressed(i, Keyboard.isKeyDown(i)); | |
} | |
} | |
public boolean isPressed(int key){ | |
return keyStatesMap.get(key); | |
} | |
public void setPressed(int key, boolean pressed){ | |
keyStatesMap.put(key, pressed); | |
} | |
public boolean isKeyboardKeyPressed(int key){ | |
return isPressed(key); | |
} | |
public void setKeyboardKeyPressed(int key, boolean pressed){ | |
setPressed(key, pressed); | |
} | |
public boolean isKeyboardKeyPressed(String key){ | |
return isKeyboardKeyPressed(Keyboard.getKeyIndex(key)); | |
} | |
public void setKeyboardKeyPressed(String key, boolean pressed){ | |
setKeyboardKeyPressed(Keyboard.getKeyIndex(key), pressed); | |
} | |
public boolean isMouseKeyPressed(int key){ | |
return isPressed(-100 + key); | |
} | |
public void setMouseKeyPressed(int key, boolean pressed){ | |
setPressed(-100 + key, pressed); | |
} | |
public boolean isMouseKeyPressed(String key){ | |
return isMouseKeyPressed(Mouse.getButtonIndex(key)); | |
} | |
public void setMouseKeyPressed(String key, boolean pressed){ | |
setMouseKeyPressed(Mouse.getButtonIndex(key), pressed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment