Created
April 27, 2013 17:39
-
-
Save warmwaffles/5473915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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