moveFromDirection method

bool moveFromDirection(
  1. Direction direction, {
  2. bool enabledDiagonal = true,
})

Implementation

bool moveFromDirection(Direction direction, {bool enabledDiagonal = true}) {
  switch (direction) {
    case Direction.left:
      return moveLeft(speed);
    case Direction.right:
      return moveRight(speed);
    case Direction.up:
      return moveUp(speed);
    case Direction.down:
      return moveDown(speed);
    case Direction.upLeft:
      if (enabledDiagonal) {
        return moveUpLeft(speed * REDUCTION_SPEED_DIAGONAL,
            speed * REDUCTION_SPEED_DIAGONAL);
      } else {
        return moveRight(speed);
      }

    case Direction.upRight:
      if (enabledDiagonal) {
        return moveUpRight(speed * REDUCTION_SPEED_DIAGONAL,
            speed * REDUCTION_SPEED_DIAGONAL);
      } else {
        return moveRight(speed);
      }

    case Direction.downLeft:
      if (enabledDiagonal) {
        return moveDownLeft(speed * REDUCTION_SPEED_DIAGONAL,
            speed * REDUCTION_SPEED_DIAGONAL);
      } else {
        return moveLeft(speed);
      }

    case Direction.downRight:
      if (enabledDiagonal) {
        return moveDownRight(speed * REDUCTION_SPEED_DIAGONAL,
            speed * REDUCTION_SPEED_DIAGONAL);
      } else {
        return moveRight(speed);
      }
  }
}