Bouncing Circle: Make it bouncy, pt. 3

⌨️ Add code to reverse the circle’s direction

image

Looks funny, but let’s think through this.

After hitting the wall, we want the circle to go in the opposite direction, which means we want its new speed to be opposite of the old speed.

If the old speed is 1, the new speed should be -1.

If the old speed is 8, the new speed should be -8.

If the old speed is 592819, then the new speed should be -592819.

Whatever xSpeed is, to get the new speed you just need to multiply the old speed by -1.

That’s what the code says!

“set xSpeed equal to xSpeed multiplied by negative one”

Next up...

Bouncing Circle: Make it bouncier