pic 1

In this game I am still having a problem with the collision. The collision works fine but if I am bumping in to the wall and then turn around I end up going backwards through the wall. My code is a simple if sprite collision(#,#)=1 and image=# then X=X-# to push it back. Any thoughts on how to shrink my code and stop me from backing through the wall?
if sprite collision(1,65)=1 and image=7 then xpos=xpos+5
if sprite collision(1,65)=1 and image=3 then xpos=xpos-5
if sprite collision(1,65)=1 and image=1 then ypos=ypos+5
if sprite collision(1,65)=1 and image=5 then ypos=ypos-5
if sprite collision(1,65)=1 and image=2 then xpos=xpos-5 : ypos=ypos+5
if sprite collision(1,65)=1 and image=4 then xpos=xpos-5 : ypos=ypos-5
if sprite collision(1,65)=1 and image=6 then xpos=xpos+5 : ypos=ypos-5
if sprite collision(1,65)=1 and image=8 then xpos=xpos+5 : ypos=ypos+5
On target, On time!