refactor game controller move
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
</layer>
|
</layer>
|
||||||
<layer id="3" name="water" width="18" height="16">
|
<layer id="3" name="water" width="18" height="16">
|
||||||
<data encoding="base64" compression="zlib">
|
<data encoding="base64" compression="zlib">
|
||||||
eJxjYBgFo2AUjIKBAQAEgAAB
|
eJxjYBgFo2AUjALKgRES25BIPQAWUABk
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
<layer id="4" name="water2" width="18" height="16">
|
<layer id="4" name="water2" width="18" height="16">
|
||||||
|
|||||||
@@ -12,81 +12,33 @@ public class GameControllerState implements ControllerState {
|
|||||||
this.controllerEntities = controllerEntities;
|
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
|
@Override
|
||||||
public void keyDown(Command command) {
|
public void keyDown(Command command) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case UP:
|
case UP -> moveEntities(0f, 1f);
|
||||||
for (Entity entity : controllerEntities) {
|
case DOWN -> moveEntities(0f, -1f);
|
||||||
Move move = Move.MAPPER.get(entity);
|
case LEFT -> moveEntities(-1f, 0f);
|
||||||
if (move != null) {
|
case RIGHT -> moveEntities(1f, 0f);
|
||||||
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:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyUp(Command command) {
|
public void keyUp(Command command) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case UP:
|
case UP -> moveEntities(0f, -1f);
|
||||||
for (Entity entity : controllerEntities) {
|
case DOWN -> moveEntities(0f, 1f);
|
||||||
Move move = Move.MAPPER.get(entity);
|
case LEFT -> moveEntities(1f, 0f);
|
||||||
if (move != null) {
|
case RIGHT -> moveEntities(-1f, 0f);
|
||||||
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:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user