How to fix it? A object does not push 2 objects at the same time

How to prohibit the white object push two red objects when these two objects collide?
My code is here:

Your code is quite messy…

Remember it is always better to divide the logics. Make a class for the player and a class for the blocks…

and anyway, why don’t you use a collision system instead of writing one by yourself?
Something like this one it is very interesting

After you just have to check collision between player and all the blocks, and if there is one check if that block collide with another one in the same direction.

I don’t know what you have in mind, but if you don’t have confidence with mathematical algorithms it is better to use what other people already wrote.

there are so many physics engine, or just collision engine that could be very useful for you and help you to focus on the gameplay instead of the mathematics behind.

Just an advice :wink:
happy coding man