diff --git a/assets/maps/mainmap.tmx b/assets/maps/mainmap.tmx
index 50ec2aa..73f9c89 100644
--- a/assets/maps/mainmap.tmx
+++ b/assets/maps/mainmap.tmx
@@ -12,7 +12,7 @@
- eJxjYBgFo2AUjIKBAQAEgAAB
+ eJxjYBgFo2AUjALKgRES25BIPQAWUABk
diff --git a/core/src/main/java/io/github/com/quillraven/input/GameControllerState.java b/core/src/main/java/io/github/com/quillraven/input/GameControllerState.java
index 01aefb8..d420e7e 100644
--- a/core/src/main/java/io/github/com/quillraven/input/GameControllerState.java
+++ b/core/src/main/java/io/github/com/quillraven/input/GameControllerState.java
@@ -12,81 +12,33 @@ public class GameControllerState implements ControllerState {
this.controllerEntities = controllerEntities;
}
+ private void moveEntities(float dx, float dy) {
+ for (Entity entity : controllerEntities) {
+ Move move = Move.MAPPER.get(entity);
+ if (move != null) {
+ move.getDirection().x += dx;
+ move.getDirection().y += dy;
+ }
+ }
+ }
+
@Override
public void keyDown(Command command) {
switch (command) {
- case UP:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().y += 1f;
- }
- }
- break;
- case DOWN:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().y -= 1f;
- }
- }
- break;
- case LEFT:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().x -= 1f;
- }
- }
- break;
- case RIGHT:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().x += 1f;
- }
- }
- break;
- default:
+ case UP -> moveEntities(0f, 1f);
+ case DOWN -> moveEntities(0f, -1f);
+ case LEFT -> moveEntities(-1f, 0f);
+ case RIGHT -> moveEntities(1f, 0f);
}
}
@Override
public void keyUp(Command command) {
switch (command) {
- case UP:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().y -= 1f;
- }
- }
- break;
- case DOWN:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().y += 1f;
- }
- }
- break;
- case LEFT:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().x += 1f;
- }
- }
- break;
- case RIGHT:
- for (Entity entity : controllerEntities) {
- Move move = Move.MAPPER.get(entity);
- if (move != null) {
- move.getDirection().x -= 1f;
- }
- }
- break;
- default:
+ case UP -> moveEntities(0f, -1f);
+ case DOWN -> moveEntities(0f, 1f);
+ case LEFT -> moveEntities(1f, 0f);
+ case RIGHT -> moveEntities(-1f, 0f);
}
}
}