CSE 131 Module 4: Input & Output
Before beginning any work, do a Team...Pull in your repository.
In this lab you will simulate multiple bouncing balls, that may bump
into each other or into the wall. The steps articulated below for completing
this lab recommend that you develop the code in stages, so that you can test
as you go and make sure you are on the right track.
You have the knowledge you need to do this assignment, but the assignment
is written-up in a style usually seen for software specification: you are
told what should happen, but it's up to you to make it happen.
As always, consult with TAs when you are stuck.
The code you submit must be your own!
We are not interested in solutions you find on the Internet. We are interested
in your implementation of these ideas.
- Do your work in the lab4 package of the labs source
folder, in the BumpingBalls class.
Review the implementation of BouncingBall,
found in the coursesupport
source folder, package book.ch1.
- Review the additions we made to BouncingBall to obtain
DeluxeBouncingBall, found in the labsupport source folder,
- We added sound when an object changed direction.
- We replaced the ball by images.
- While there is some physics required for this lab, the information
you need to know is simply the following:
- Two balls are colliding if the distance between the two balls' centers
is less than the sum of the two balls' radii:
- The distance between two points can be computed
using the distance formula.
- Prompt the user for the number of balls that will be simulated in
your program and the number of iterations for the simulation.
- For each ball, find a random place on the screen to place that ball.
- For each ball, compute a random velocity for that ball.
Based on what you have learned so far in this course, how will you keep
track of the balls' positions and velocities?
Finding a reasonable range of velocities may require some trial-and-error, or
some thinking and experimentation using pencil and paper:
- If the balls move
too fast, they might fly off the screen.
- If they move too slowly, the simulation will take forever for you to see something.
- Iterate the specified number of times, each time recomputing
each ball's location
- When a ball collides with a wall, change its velocity as shown
in the BouncingBall program.
- When a ball collides with another ball, change both its horizontal and
vertical velocity component, as if the ball hit a corner of the screen.
- For extra fun, have the balls replaced by images you like. There
are some in the images folder in your repo, but you are free
to find others. Be sure to commit those to your repository.
- For extra extra fun, play sounds when balls collide. Some of those can be found
in the sound folder.
Submitting your work (read carefully)
- You must commit and push all of your work to your repository. It's best to do this
from the top-most level of your repository, which bears your name and student ID.
- You must demo the commited work to a TA. Make sure the TA knows that
your demo is for credit at this point.
- Follow the directions below to have your demo for this work recorded.
Last modified 14:43:35 CDT 15 June 2018
When you are done with this lab, you must be cleared by the TA to receive credit.
- Do a Team…Pull to update your repository. You must do this or the commit/push below may fail.
- Commit and push all your work to your repository.
certain this has worked by logging into
bitbucket. There you
will see the commit(s) in your news feed if it was successful. You can also
check the Source page to locate and ensure your code was received.
It is your responsibility to make certain the code has been pushed.
Some of your work receives credit through testing of your pushed code. You
will receive no credit for such work if you failed to push. We generally
reserve the right to revoke credit for any of your work that has not been
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in the TA's name
- Click OK while the TA watches
- If you request propagation, it does not happen immediately,
but should be posted in the next day or so
This demo box is for lab 4