Something like this would work:
give the sprite 8 direction behaviour set to 4 directions
give the sprite an instance variable Direction
Sprite if variable direction = 1 - simulate pushing right
Sprite if variable direction = 2 - simulate pushing down
Sprite if variable direction = 3 - simulate pushing left
Sprite if variable direction = 4 - simulate pushing up
sprite compare x = more than 400 <-- (or whatever number you want)
sprite if variable = 1 - sprite set variable to 2
sprite compare y = more than 400
sprite if variable = 2 - sprite set variable to 3
sprite compare x = less than 100
sprite if variable = 3 - sprite set variable to 4
sprite compare y = less than 100
sprite if variable = 4 - sprite set variable to 1