The Box class has a state that determines which direction it's heading.
The state will change if the box hits a wall or if the mouse is clicked.

Source code: week12_state Box

Built with Processing