Project 2.6: Gravity
Count the bounces a ball makes as it crosses the screen
Your program will have a ball that moves across the screen as is affected by gravity
The ball must always start in the top left corner
The ball should have a random x speed
When the ball hits the bottom of the screen, it should reverse direction
When bouncing, it the y speed of the ball will randomly be reduced to between 70% and 90% of its previous y speed due to friction.
When the ball hits the right side of the screen, it should "reset" to the top left with a new random starting speed
Your program will display the number of bounces
Show how many bounces the current ball has on the screen and update it in real time
Show how many bounces the record ball has had.
FAQ / Tips
How do I slow the ball down to 70% to 90% of it's previous speed.
Multiply the ySpeed by a random number between 0.7 and 0.9.
My ball is getting stuck once I slow it down! HELP!
You'll want to use this line of code to reverse the ball, rather than simply mulitplying by negative one.
This ensures the ball will always move upward, even if it's moving slower and can't get back above zero.
Wait, how do I draw text? We didn't learn that yet!
You can read the Coder's Handbook Text entry for full information. This is actual something we'll fully dig into as part of our next project. For your convinence, below is some sample code to draw text. Note: You'll need to create and assign values to these variables: