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 inside to the same color of your choosing.
      • Set the speeds to random values in the range [-5, 5)
    • move()
      • Do not increase speed when the wall gets hit.
    • public void setColor(color newc)
      • Set inside to newc
    • public boolean collisionCheck(Ball other)
      • Returns true if the calling ball object and other are touching, false otherwise.
      • You will need to check the distance between the 2 Ball objects.

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 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.