Use this "if bgget(layer,spriteX+5,spriteY,1)>0 then spriteX=spriteX-1" and change it accordingly. That line will move your sprite left after making contact wall while moving right. Make sure to put the collision inside the main loop.