Project #3: Bounce
Balls that bounce off the edge of the screen
REQUIREMENTS
Your program will have at least two balls that bounce off the edges of the screen
They should properly reflect at the correct angle
They can phase through each other - don't worry about collisions
Each ball should...
Start at a different location on the screen
Have a different xSpeed and ySpeed
Bounce correctly off the edges to account for with and height - your ball should not "phase" into the wall
When they hit the side of the screen
The first ball should change to a random warm color (red, orange, etc)
The second ball should change to a random cool color (blue, green, etc).
FAQ / Tips
Progression Advice
Draw a single stationary ball
Make the ball move
Make the ball bounce off the edge
Make sure it bounces right off the edge and doesn't push into any edges
Repeat with a second ball
Wait, but how do I make the ball bounce?
Read Coder's Handbook - Animation carefully. If you want more help, look at Shiffman's bouncing ball example linked on that page.
Is there a way to do this program without repeating so much code?
Yes - but it's beyond your powers right now. We'll come back to this!
I know it's not required, but ... how do I make the balls hit each other?
You'll need to see if one ball is inside of the other one. You have their x positions and y positions, as well as their sizes. If one ball is within another's radius....
EXTRA CREDIT IDEAS
You can do these extra credit options or come up with your own. Note that your instructor won't help you solve these problems - they are meant to be additional challenges to do on your own!
Option 1 - Fancier Bounces
Have your ball grow when it bounces and shrink when it gets to be too big
Have your ball accelerate when it bounce and slow when it gets too fast
These are more complicated than they sound! You'll have to think a bit about the ways bouncing works when the ball is outside of the bounds for more than one frame...
Option 2 - Collision
Have the two balls collide bounce off each other
EXAMPLE: RUNNING PROGRAM
Lines were added to show predicted motion. They are not displayed in the program.