Defining metode for evil circle


  • Inside the if() statements, if the tests return true we don’t want to update velX / velY ; we want to instead change the value of x / y so the evil circle is bounced back onto the screen slightly. Adding or subtracting (as appropriate) the evil circle’s size property would make sense.

I’m really stuck at this part, is there someone who can direct me, if open my mind or how should I think to complete this step and the next?

Hi @samuelharold327

The checkBounds() needs to look similar to update() of the bouncing balls and has the same conditions. The difference is what we do when a condition is true. Since the evil circle is controlled by the user over the keyboard we just want to push it back when we detect that it’s outside the canvas.
When we detect that the circle would leave the right side of the canvas (x-position + size is bigger then width of canvas), we simply subtract the size from the x-position and assign it to the x-position as the new value. This way the circle is back inside the canvas.

Does that make it clearer?

Happy coding,


clear,thank you.

sangat jelas,terimasih, ini sedikit membantu membuka pikiran saya.

1 Like