Oxidation states of oxygen
The concept of oxidation state simply works on concept of electronegativity.The more electronegative atom acquire a negative charge while less electronegative atom acquire a positive charge.
Depending on this hypothesis oxygen have 5 oxidation states.


In all the oxides,oxygen has an oxidation state of $-2$. Eg. $\ce{CO2,CO}$
In all peroxides (oxygen-oxygen linkage), oxygen has an oxidation state of $-1$. For example, consider $\ce{H2O2}$, here $\ce{H}$ is less electronegative so it will acquire a charge of $+1$ and to balance the $2$ positive charge of 2 H-atoms,each oxygen atom will acquire a charge of $-1$.
In all superoxides ($\ce{KO2,CsO2,RbO2}$), oxygen has an oxidation state of $-\frac{1}{2}$,this is because $\ce{K,Cs,Rb}$, being elements of the first group and less electronegative than oxygen acquire a charge of $+1$, to balance it, each oxygen atom acquires a charge of  $-\frac{1}{2}$.
In one of the exceptions $\ce{OF2}$, the fluorine being more electronegative acquires a charge of $-1$ and to balance the $-2$ charge of 2 fluorine atoms oxygen acquires a charge of $+2$.
As last, there is $\ce{O2F2}$, similarly here to balance the $-2$ charge on 2 $\ce{F}$-atoms each oxygen atom acquire a charge of $+1$.