Due: Thursday 10/31 10:00am
Submission name: w20_collision
When submitting, make sure to submit the whole processing sketch folder with the driver and Ball class files.
Reference Image:
First, get the starter code
Start with a working version of the object based bouncing ball program. get it here. Add these 2 lines to the top of your driver file, they will provide color
values that you will be using in this assignment.
color SAFE_COLOR = color(0, 255, 255);
color COLLISION_COLOR = color(255, 0, 255);
Add the following to the Ball
class:
- Instance Variables:
color c
: represents the intended fill color of aBall
object.
- Methods:
- Constructor
- Set
c
toSAFE_COLOR
. - Set the speeds to random values in the range [-5, 5]
- Set
display()
- Modify this so the Ball object has the appropriate fill color.
void setColor(color newc)
- Set the color instance variable to
newc
- Set the color instance variable to
boolean collisionCheck(Ball other)
- Returns
true
if the calling ball object andother
are touching,false
otherwise. - You will need to check the distance between the 2 Ball objects.
- Returns
- Constructor
Modify the driver file as follows:
setup
- Make the screen 400x400 (smaller to make collisions more likely).
- Create two
Ball
objects using the default constructor.
draw
- Check if the two
Ball
objects are touching. - If they are, set the color instance variable of each to
COLLISION_COLOR
. - If not set the color instance variable of each to
SAFE_COLOR
.
If you get everything working, try this with 3 balls.