Implemented moving Character
This commit is contained in:
@@ -5,10 +5,15 @@
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -20,24 +25,70 @@ 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) {
|
||||
if(keycode == Input.Keys.Q) {
|
||||
CommandStream.registerCommand(testCommand);
|
||||
} else if(keycode == Input.Keys.C) {
|
||||
CommandStream.registerCommand(menuCommand);
|
||||
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) {
|
||||
return false;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user