Help me

alright say that you have a game were a block goes back and

fourth and if the block hits a wall it will stop and just not move in

that direction. how would i do this… thanks in advance