Try out the staff’s solution again (via ~cs50/pset4/breakout from within your own ~/Dropbox/pset4 directory) to remind yourself how our implementation behaves. Yours doesn’t need to be identical. In fact, all the better if you personalize yours. But playing with our implementation should help guide you toward yours.

Implement initPaddle . Per the function’s return value, your paddle should be implemented as a GRect . Odds are you’ll first want to decide on a width and height for your paddle, perhaps declaring them both atop breakout.c with constants. Then calculate coordinates (x and y) for your paddle, keeping in mind that it should be initially aligned in the bottom-middle of your game’s window. We leave it to you to decide exactly where. Odds are some arithmetic involving the window’s width and height and the paddle’s width and height will help you center it. Keep in mind that x and y refer to a GRect 's top-left corner, not its own middle. Your paddle’s size and location doesn’t need to match the staff’s precisely, but it should be perfectly centered, near the window’s bottom. You’re welcome to choose a color for it too, for which setColor and setFilled might be of interest. Finally, instantiate your paddle with newGRect . (Take note of that function’s prototype at http://cdn.cs50.net/2013/fall/psets/4/pset4/pset4/spl/doc/gobjects.html.) Then return the GRect returned by newGRect (rather than NULL , which the distribution code returns only so that the program will compile without initPaddle fully implemented).

Now, initPaddle 's purpose in life is only to instantiate and return a paddle (i.e., GRect ). It shouldn’t handle any of the paddle’s movement. For that, turn your attention to the TODO up in main . Proceed to replace that TODO with some lines of code that respond to a user’s mouse movements in such a way that the paddle follows the movements, but only along its (horizontal) x-axis. Look back at cursor.c for inspiration, but keep in mind that cursor.c allowed that circle to move along a (vertical) y-axis as well, which we don’t want for Breakout, else the paddle could move anywhere (which might be cool but not exactly Breakout).

Now turn your attention to the TODO in initBricks . Implement that function in such a way that it instantiates a grid of bricks (with ROWS rows and COLS columns), with each such brick implemented as a GRect . Drawing a GRect (or even a bunch of them) isn’t all that different from drawing a GOval (or circle). Odds are, though, you’ll want to instantiate them within a for loop that’s within a for loop. (Think back to mario , perhaps!) Be sure to leave a bit of a gap between adjacent bricks, just like we did; exactly how many pixels is up to you. And we leave it to you to select your bricks' colors.

Now implement initBall , whose purpose in life is to instantiate a ball in the window’s center. (Another opportunity for a bit of arithmetic!) Per the function’s prototype, be sure to return a GOval .

Then, back in main , where there used to be a TODO , proceed to write some additional code (within that same while loop) that compels that ball to move. Here, too, take baby steps. Look to bounce.c first for ideas on how to make the ball bounce back and forth between your window’s edges. (Not the ultimate goal, but it’s a step toward it!) Then figure out how to make the ball bounce up and down instead of left and right. (Closer!) Then figure out how to make the ball move at an angle. Then, utilize drand48 to make the ball’s initial velocity random, at least along its (horizontal) x-axis. Note that, per its man page, drand48 returns "nonnegative double-precision floating-point values uniformly distributed between [0.0, 1.0)." In other words, it returns a double between 0.0 (inclusive) and 1.0 (exclusive). If you want your velocity to be faster than that, simply add some constant to it and/or multiply it by some constant! Ultimately, be sure that the ball still bounces off edges, including the window’s bottom for now.

When ready, add some additional code to main (still somewhere inside of that while loop) that compels the ball to bounce off of the paddle if it collides with it on its way downward. Odds are you’ll want to call that function we wrote, detectCollision , inside that loop in order to detect whether the ball’s collided with something so that, if so, you can somehow handle such an event. Of course, the ball could collide with the paddle or with any one of those bricks. Keep in mind, then, that detectCollision could return any such GObject ; it’s left to you to determine what has been struck. Know, then, that if you store its return value, as with GObject object = detectCollision(window, ball); you can determine whether that object is your game’s paddle, as with the below. if (object == paddle) { } More generally, you can determine if that object is a GRect with: if (strcmp(getType(object), " GRect " ) == 0 ) { } Once it comes time to add a GLabel to your game (for its scoreboard), you can similarly determine if that object is GLabel , in which case it might be a collision you want to ignore. (Unless you want your scoreboard to be something the ball can bounce off of. Ours isn’t.) if (strcmp(getType(object), " GLabel " ) == 0 ) { }

Once you have the ball bouncing off the paddle (and window’s edges), focus your attention again on that while loop in main and figure out how to detect if the ball’s hit a brick and how to remove that brick from the grid if so. Odds are you’ll find removeGWindow of interest, per http://cdn.cs50.net/2013/fall/lectures/5/m/src5m/spl/doc/gwindow.html. SPL’s documentation incorrectly refers to that function as remove , but it’s indeed removeGWindow you want, whose prototype, to be clear, is the below. void removeGWindow(GWindow gw, GObject gobj);

Now decide how to determine whether the ball has zoomed past the paddle and struck the window’s bottom edge, in which case the user should lose a life and gameplay should probably pause until the user clicks the mouse button, as in the staff’s implementation. Odds are detecting this situation isn’t all that different from the code you already wrote for bouncing; you just don’t want to bounce off that bottom edge anymore!