/* Copyright 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.Controller;
import org.lwjgl.util.vector.Vector2f;
import ponkOut.Settings;
public class ControllerInput implements InputDevice {
private Controller controller;
private float speed;
private ControllerAction controllerUp;
private ControllerAction controllerDown;
private ControllerAction controllerLeft;
private ControllerAction controllerRight;
private ControllerAction controllerFire;
public ControllerInput(int player) {
Settings settings = Settings.getInstance();
controller = InputManager.getInstance().getController(settings.getControllerIndex(player));
speed = settings.getControllerSpeed(player) * 4.0f;
controllerUp = settings.getControllerUp(player);
controllerDown = settings.getControllerDown(player);
controllerLeft = settings.getControllerLeft(player);
controllerRight = settings.getControllerRight(player);
controllerFire = settings.getControllerFire(player);
}
@Override
public Vector2f getMovement(float elapsedTime) {
Vector2f v = new Vector2f(controllerRight.getAction(controller) - controllerLeft.getAction(controller),
controllerUp.getAction(controller) - controllerDown.getAction(controller));
v.scale(speed);
return v;
}
@Override
public boolean isButtonDown() {
return controllerFire.getAction(controller) > 0.5f;
}
}