i’m new in this of programming but i am trying to learn by making this sort of codes. I would like the ball and the wall1 interact each other making the ball bounce on the brick.
May somebody guide me, please?
I’ve tried to make ‘minimal changes’ in the sense that you’ll hopefully recognize how I changed your code. I only introduced a new concept of paddles (which is only an array of instances of your wall class).
I moved the ‘boundary collision’ code into its own function & created a similar function to do ‘paddle/wall collision checking’, and I’m only doing what you could call a ‘simple collision’ between a box & a single point (the center of the circle). for determining the angle the ball will bounce back in (the ball’s yspeed), i decided to go with the 'distance between the ball and the center of the paddle!
and set the y-speed to the ‘y difference’ of the ball and the center of the paddle (hence paddle.y + paddle.h / 2). The 10 is a magic number that ‘felt right’ since the ‘pixel distance’ given by the y-difference calculation was a bit too much, so I wanted to scale that down a bit.