/**
* TimeHero - http://timehero.sf.net
*
* @license See LICENSE
*/
package it.timehero.util;
import it.timehero.slick.states.MenuPauseState;
import it.timehero.world.AttackNotify;
import it.timehero.world.MovementNotify;
import it.timehero.world.WorldEngine;
import java.util.Observable;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;
/**
* Gestisce gli input dell'utente e li notifica al WorldEngine
*
* @author AM
* @project Timehero0.2
*/
public class UserInputController extends Observable {
public UserInputController(WorldEngine we){
addObserver(we);
}
/**
* All'input dell'utente notifica al WorldEngine la sua mossa
*
* @param container
* @param game
* @param delta
*/
public void getInput(GameContainer container, StateBasedGame game, int delta){
if (container.getInput().isKeyDown(Input.KEY_ESCAPE)) {
game.enterState(MenuPauseState.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
}
// gestione controlli
boolean keyRight = container.getInput().isKeyDown(Input.KEY_RIGHT) ;
boolean keyLeft = container.getInput().isKeyDown(Input.KEY_LEFT) ;
boolean keyUp = container.getInput().isKeyDown(Input.KEY_UP) ;
boolean keyDown = container.getInput().isKeyDown(Input.KEY_DOWN) ;
boolean keySpace = container.getInput().isKeyDown(Input.KEY_SPACE) ;
// associazione tasto/funzione
if (keyRight) {
// gigi si deve muovere, notifico il cambiamento agli osservatori
setChanged();
notifyObservers(new MovementNotify(Helper.GIGI,Helper.RIGHT_DIR,delta));
}
if (keyLeft) {
// gigi si deve muovere, notifico il cambiamento agli osservatori
setChanged();
notifyObservers(new MovementNotify(Helper.GIGI,Helper.LEFT_DIR,delta));
}
if (keyUp) {
// gigi si deve muovere, notifico il cambiamento agli osservatori
setChanged();
notifyObservers(new MovementNotify(Helper.GIGI,Helper.UP_DIR,delta));
}
if (keyDown) {
// gigi si deve muovere, notifico il cambiamento agli osservatori
setChanged();
notifyObservers(new MovementNotify(Helper.GIGI,Helper.DOWN_DIR,delta));
}
if (keySpace) {
// gigi vuole attaccare
setChanged();
notifyObservers(new AttackNotify(Helper.GIGI,delta));
}
}
}