if you haven't found a solution I think I found one.
find the differences x-xprevious and y-yprevious and add them together. that value will be called SUM for the sake of not being confusing.
do two place_free()s, one at (x+SUM,y) one at (x, y+SUM). this should serve as a collision check like this
the exact orientation depends on the direction your going and what adding and subtracting you do at the place_free points. if you want to switch directions, make suse to multiply SUM by -1 in one of the place free() points. you could say something like SUM*the sign of(direction-91).
this should work, I think. I just thought it up off the top of my head, so it is not tested. the important idea though is the difference between x and xprevious, and the y equivalent, since one of them will always be zero if you restrict your movement to horizontal and vertical.
people have already suggested this method, but this is just a way to implement it.
it shouldn't work on slopes though, that's beyond me...