125 lines
3.5 KiB
Java
125 lines
3.5 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.darkrp2d.input;
|
|
|
|
import com.badlogic.ashley.core.Entity;
|
|
import com.badlogic.ashley.core.Family;
|
|
import com.badlogic.gdx.Input;
|
|
import com.badlogic.gdx.InputProcessor;
|
|
import com.darkrp2d.DarkRP2D;
|
|
import com.darkrp2d.entities.components.ControllableComponent;
|
|
import com.darkrp2d.entities.components.PhysicComponent;
|
|
import com.darkrp2d.input.commands.*;
|
|
import com.darkrp2d.input.commands.moveCommands.*;
|
|
import com.darkrp2d.scenes.menu.MenuScreen;
|
|
|
|
/**
|
|
*
|
|
* @author gulum
|
|
*/
|
|
public class InputHandler implements InputProcessor {
|
|
|
|
Command testCommand;
|
|
Command menuCommand;
|
|
|
|
//MovementCommands
|
|
Command upCommand;
|
|
Command downCommand;
|
|
Command leftCommand;
|
|
Command rightCommand;
|
|
|
|
public InputHandler(DarkRP2D game) {
|
|
testCommand = new TestCommand();
|
|
this.menuCommand = new MenuCommand(game, new MenuScreen(game));
|
|
|
|
//Inputs auf erstes bedienbares entity
|
|
Entity character = game.engine.getEntitiesFor(Family.all(ControllableComponent.class, PhysicComponent.class).get()).first();
|
|
this.upCommand = new UpCommand(character);
|
|
this.downCommand = new DownCommand(character);
|
|
this.leftCommand = new LeftCommand(character);
|
|
this.rightCommand = new RightCommand(character);
|
|
}
|
|
|
|
@Override
|
|
public boolean keyDown(int keycode) {
|
|
switch (keycode) {
|
|
case Input.Keys.Q:
|
|
CommandStream.registerCommand(testCommand);
|
|
break;
|
|
case Input.Keys.C:
|
|
CommandStream.registerCommand(menuCommand);
|
|
break;
|
|
case Input.Keys.W:
|
|
CommandStream.registerCommand(upCommand);
|
|
break;
|
|
case Input.Keys.S:
|
|
CommandStream.registerCommand(downCommand);
|
|
break;
|
|
case Input.Keys.A:
|
|
CommandStream.registerCommand(leftCommand);
|
|
break;
|
|
case Input.Keys.D:
|
|
CommandStream.registerCommand(rightCommand);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean keyUp(int keycode) {
|
|
switch (keycode) {
|
|
case Input.Keys.W:
|
|
CommandStream.registerCommand(upCommand);
|
|
break;
|
|
case Input.Keys.S:
|
|
CommandStream.registerCommand(downCommand);
|
|
break;
|
|
case Input.Keys.A:
|
|
CommandStream.registerCommand(leftCommand);
|
|
break;
|
|
case Input.Keys.D:
|
|
CommandStream.registerCommand(rightCommand);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean keyTyped(char character) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean mouseMoved(int screenX, int screenY) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean scrolled(int amount) {
|
|
return false;
|
|
}
|
|
|
|
}
|