'Collusion with wall in pygame [duplicate]

I am planning to make collusion with the wall, so that if the player collides with the wall then the player cannot move toward the wall anymore.

However, I don't know how to code it. Do I have to use impulse and newton's third law, so if the player collides with the wall and presses the button toward it, then the player receives the same amount of force from the wall so can't move.

Can anyone show an example?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source