Posted: Thu Nov 5
Due: Friday 11/6 10:00am
Submission name: w22_collision
First, get the starter code
Start with a working version of the object based bouncing ball program, which you can get from thesource if you need it.
Add the following to the Ball class:
- Methods:
- Constructors (both)
- Set
insideto the same color of your choosing. - Set the speeds to random values in the range [-5, 5)
- Set
move()- Do not increase speed when the wall gets hit.
public void setColor(color newc)- Set
insidetonewc
- Set
public boolean collisionCheck(Ball other)- Returns
trueif the calling ball object andotherare touching,falseotherwise. - You will need to check the distance between the 2 Ball objects.
- Returns
- Constructors (both)
Modify the driver file as follows:
setup
- Make the screen 400x400 (smaller to make collisions more likely).
- Create two
Ballobjects using the default constructor.
draw
- Check if the two
Ballobjects are touching. - If they are, set the color instance variable of each to a different color from the one used in the constructors.
- If they are not touching, the color should be the one from the constors.
- If you get everything working, try this with 3 balls.