Due: Thursday 11/21 10:00am
Submission name: work27_blast
Start by grabbing the modified Ball
class code from thesource
. You can find it in a new directory called Classes
. This is similar to the Ball
class with the following changes (these are already done, you need not change them):
- The center of the ball is now a
PVector
. - The constructor takes the center of the ball and size as arguments.
Create a driver file with the following:
- Global variables:
Ball[][] grid
Ball projectile
- You make also want to include other constants as needed.
setup()
- Instantiate
grid
to a 3 (rows) x 5 (cols) 2D array. - Call
makeBalls()
- Call
newProjectile()
- Instantiate
draw()
- Clear the screen.
- Call
drawGrid()
- Move and display
projectile
- Call
processCollisions)()
keyPressed()
:- space: set the
yspeed
ofprojectile
to-1
- LEFT/RIGHT: move
projectile
left/right
- space: set the
void makeBalls(Ball[][] g)
- Populates
g
withBall
objects. They should all be the same size, arranged such that each ball is a size distance away from its neighboringBall
objects.
- Populates
void newProjectile(int psize)
- Set
projectile
to a newBall
at the bottom center of the screen.
- Set
void drawGrid(Ball[][] g)
- Draw all the
Ball
objects ing
- Draw all the
void processCollisions(Ball p, Ball[][] g)
- Check if
p
collides with anyBall
objects ing
. - If so, set the entry in the array to
null
, and callnewProjectile
- Check if