In this case, you can add a new variable: e.g. horizontal_mode
then you only need to change the code for phase==1
if horizontal mode is true: set x to change with constant speed, y keep the same
if horizontal is false: keep the original code