0

i'm currently working on breakout.c, but i'm having trouble with the ball continuing to bounce off the bottom even after it drops below the paddle (step 9 of the spec walkthrough). Instead, I want it to return to a specific location and then pause until the user clicks again.

I'm not quite sure where i'm going wrong, and i've searched through this site/google and can't seem to find tips on this specific issue. Someone on the slack channel pointed me in the right direction re: coordinates, but it doesn't seem to have made an impact. I've tried it several ways already, including putting it in another loop that checks for null (even though i'm not sure that would make sense given that it's in the while loop that already does that?)

Here is what I think is the relevant code snippet:

while (lives > 0 && bricks > 0)
{
 ....

     // minus one life if ball falls to the bottom --not working
         else if (getY(ball) >= 600)
         {   
           lives = lives - 1;
           waitForClick();
           setLocation(ball, 150, 300);
         }
        .....
}

1 Answer 1

1

First consider instead of just getY(ball) to also add two times the diameter of the ball so by the time the bottom of the ball hits the bottom of the screen you count a lost life. Also it's not a good practise to use magic numbers (see 600). Instead use a constant declared at top, and use it in your code. Now aside from that, I don't know what setLocation is, but instead you can remove the ball by removeGWindow(window, ball); and then use ball = initBall(window); to make the ball appear again where it started. If you want to add it to a different location, just copy the code from initBall() and use it in another function (I guess that is what your setLocation() does) and then change the coordinates. If you want to wait for the user's click use the waitForClick() function. Other than that I don't think there is something wrong/more to be done by this if block. If this doesn't solve your problem, consider adding a little bit more code.

2
  • waitForClick() is a function of what library? can you tell me where did you get this function from and its documentation plz? Sep 18, 2015 at 12:14
  • Here you go. waiForClick() is a function included in the SPL library and is located under gevents.h header file. cdn.cs50.net/2014/fall/psets/3/pset3/spl/doc/…
    – ChrisG
    Sep 18, 2015 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .