M
var dir = point_direction(0,0,sign(x-xprevious>>2), sign(y-yprevious>>2));
/* assign the sprite based on dir however you want; dir will be 0, 45, 90, 135, and so on */
/* change the >>2's to change the delay between direction changes */
var d = sign(x-xprevious) + sign(y-yprevious)*3;
switch d {
case 0: /* no change */
break;
case -1: /* moving left */
break;
case -2: /* moving up and right */
break;
case -3: /* moving up */
break;
case -4: /* moving up and left */
break;
case 1: /* moving right */
break;
case 2: /* moving left and down */
break;
case 3: / moving down */
break;
case 4: /* moving down and right */
break;
}