switchDirection function optimized in Player.cpp