1
while (lives > 0 && bricks > 0)
{
    move (ball,velocity,velocity_y);

    if(getY(ball) > 555)
    {
        lives -= 1;
        remove(window,ball);
        pause(2000);
        GOval ball = initBall(window);
    }
}

My old ball is not removed and the new ball that appears does not move but instead my programme terminates.

I have also tried gdb but I'm unable to figure out the problem Someone please help me.

1
  • have you been able to solve your problem? If so, please mark any useful answer (if any) as "accepted", so other students with similar issues can benefit from your already answered question. – abelinux Dec 27 '14 at 16:20
1

Per the CS50's pset4 specs:

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);

So, your two problems are, luckily enough, the same: when you attempt to remove your "lost-live" ball, you're using the function remove, which, apparently, doesn't work very well.

Try using removeGWindow() and see what happens.

Also, as per the pset specs:

Next up are some constants, values that you don’t need to change, but because the code we’ve written (and that you’ll write) needs to know these values in a few places, we’ve factored them out as constants so that we or you could, theoretically, change them in one convenient location. By contrast, hard-coding the same number (pejoratively known as a "magic number") into your code in multiple places is considered bad practice, since you’d have to remember to change it, potentially, in all of those places.

Does that ring any bell? ;)

Jokes aside, you should start copying what's considered "good coding pratice" as soon as you recognize some patterns (or in this case, as soon as you're told by CS50's staff). In this case, perhaps you should consider changing:

if(getY(ball) > 555)

by

if(getY(ball) > (HEIGHT - 2 * RADIUS))
0

I seem to have a similar problem. My ball does get removed and the new ball appears, but the program terminates because the "lives -= 1" decrements my lives from 3 to 0 at which point the program terminates. I tried moving the "lives -= 1" down a few lines after the pause and after the ball is replaced but that didn't help. I then tried removing the "lives -= 1" and not the program does not terminate but the ball doesn't move either and the paddle seems to have a lot of lag in it after this point.

The answer to this is in the question titled "Why breakout does not restart after placing a new ball and clicking?" You don't actually want to remove the ball. You can remove the ball and replace it but for some reason it doesn't move. Go to this link and find a function the changes the location of the ball.

You must log in to answer this question.

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