/* Copyright 2010, 2012 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut. If not, see <http://www.gnu.org/licenses/>.
*/
package ponkOut.input;
import org.lwjgl.input.Keyboard;
import org.lwjgl.util.vector.Vector2f;
import ponkOut.Settings;
public class KeyboardInput implements InputDevice {
private float speed;
private int keyUp;
private int keyDown;
private int keyLeft;
private int keyRight;
private int keyFire;
public KeyboardInput(int player) {
Settings settings = Settings.getInstance();
speed = settings.getKeyboardSpeed(player) * 4.0f;
keyUp = settings.getKeyUp(player);
keyDown = settings.getKeyDown(player);
keyLeft = settings.getKeyLeft(player);
keyRight = settings.getKeyRight(player);
keyFire = settings.getKeyFire(player);
}
@Override
public Vector2f getMovement(float elapsedTime) {
Vector2f v = new Vector2f(0.0f, 0.0f);
if (Keyboard.isKeyDown(keyUp))
v.y += speed;
if (Keyboard.isKeyDown(keyDown))
v.y -= speed;
if (Keyboard.isKeyDown(keyLeft))
v.x -= speed;
if (Keyboard.isKeyDown(keyRight))
v.x += speed;
return v;
}
@Override
public boolean isButtonDown() {
return Keyboard.isKeyDown(keyFire);
}
}