CST 112 Project #5:
All code for this project should be saved
in files whose name begins with "p5".
See below for NOTES about
I N S T R U C T I O N S
- Write code to define a
as described below.
Properties should be defined within the object class;
do not use global variables for properties of these objects.
- Construct an array of several Ball objects.
- In your setup() function,
construct each of the several Ball objects
using a for loop to traverse the array.
- Write draw() and other funtions to perform actions described below.
- Write keyPressed() and mousePressed()
- Ball objects have properties such as:
- color (Random color, when constructed.)
- position and speed.
- a boolean variable to tell whether ball is "dead" or "alive".
Ball objects need methods to do the following:
- Display the ball (with proper color and number).
- Move the ball, bouncing off the walls of the table.
- Kill this ball (and remove it from the table.
- Make ball "alive" again (and reset it).
- Set random positions and speeds.
- boolean clicked()
- Return true if mouse click is near.
- The first ball
is called the the "cueball",
which should be WHITE.
- Other balls have different colors
(randomly set when constructed).
- Balls move (unless dead).
- Whenever b
gets near any other ball,
that ball is killed
(and score is increased).
- If all other balls are dead
restore all of them,
and add 10 to score.
- Game is over when score reaches 100.
Pressing a number key will reset() that ball
(to random position and speed)
-- if it is not "dead."
Note that the ball is reset()
but NOT "restored".
subtracting the value of '0'
from the key
will give the ball number,
as illustrated by the following code:
//// "Reset a ball by pressing key 1, 2, 3, etc.
int n = key - '0'; // n = number of the key.
// n=1 for '1', 2 for '2', etc.
// Use n as a subscript, to select an element of the array.
Clicking on a ball should also reset it.
Demo Code & Starter-Code:
Click here to view a working demo.
Demo code for a working program without arrays
can be found HERE:
Starter Code for your array version can be found
Your Project #5
must use an array
containing several ball objects.
regarding Remote Learning,
Since we are now in a "Remote Learning" mode, you must
save your code in your folder as you work on this project,
to show your progress.
Participate in periodic Code Reviews to discuss your code
(and to obtain help when needed).
- Each time you make code changes,
create a new file
(with a name that begins with "p5"),
to save it in your folder.
- Your coding should be discussed directly with me
during regular "Code Reviews"
(a few times per week)!
If there are no files of your preliminary code in your folder,
or if periodic code reviews have not occurred regularly,
then completed code may not be accepted or graded.