moveFromDirection method

void moveFromDirection(
  1. Direction direction, {
  2. bool enabledDiagonal = true,
  3. double? speed,
})

Implementation

void moveFromDirection(
  Direction direction, {
  bool enabledDiagonal = true,
  double? speed,
}) {
  switch (direction) {
    case Direction.left:
      moveLeft(speed: speed);
      break;
    case Direction.right:
      moveRight(speed: speed);
      break;
    case Direction.up:
      moveUp(speed: speed);
      break;
    case Direction.down:
      moveDown(speed: speed);
      break;
    case Direction.upLeft:
      if (enabledDiagonal) {
        moveUpLeft(speed: speed);
      } else {
        moveRight(speed: speed);
      }
      break;
    case Direction.upRight:
      if (enabledDiagonal) {
        moveUpRight(speed: speed);
      } else {
        moveRight(speed: speed);
      }
      break;
    case Direction.downLeft:
      if (enabledDiagonal) {
        moveDownLeft(speed: speed);
      } else {
        moveLeft(speed: speed);
      }
      break;
    case Direction.downRight:
      if (enabledDiagonal) {
        moveDownRight(speed: speed);
      } else {
        moveRight(speed: speed);
      }
      break;
  }
}