Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created April 27, 2013 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmwaffles/5473915 to your computer and use it in GitHub Desktop.
Save warmwaffles/5473915 to your computer and use it in GitHub Desktop.
public class InputTask implements Runnable {
private final ImmutableBag<Entity> entities;
public InputTask(ImmutableBag<Entity> entities) {
this.entities = entities;
}
@Override
public void run() {
for (int i = 0; i < entities.size(); i++) update(entities.get(i));
}
private void update(Entity e) {
InputC input = inputMapper.get(e);
if (input.controlling == Controlling.NotControlled) return;
if (input.controlling == Controlling.Controlling) {
input.keys = gdx.game.logic.Input.keys;
input.camDir = CameraHelper.getDirection();
}
input.process(e);
}
}
public class InputC extends Component {
public enum Controlling {
Controlling,
OtherControlled,
NotControlled
}
public Controlling controlling;
public BitSet keys;
public Vector2 camDir;
private final InputBehavior inputBehavior;
public InputC(Controlling controlling, InputBehavior inputBehavior) {
this.controlling = controlling;
this.inputBehavior = inputBehavior;
}
public void process(Entity e) {
inputBehavior.process(e);
}
}
public interface InputBehavior {
public void process(Entity e);
}
public class ShipInputBehavior implements InputBehavior {
@Override
public void process(Entity ship) {
if(input.keys.get(Keys.W) doStuff();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment