1

All my program work well till I lost my first ball. After that, I'm not able to start with an other one. I thought I've controlled that with my second while loop.

There the first part of my code in the complete above :

// keep playing until game over
while (lives > 0 && bricks > 0)
{
    // to make the ball move
    GMouseEvent click = waitForEvent(MOUSE_EVENT);

    if (getEventType(click) == (MOUSE_CLICKED))
    {
        //declarations of variables

        while (keepgoing == true)
        {

and now, here the last part of my main function, where I'm supposed to going back at the beginning :

            else if (getY(ball) <= 0)
            {
                velocity_y = -velocity_y;
            }

            else if (getY(ball) + getHeight(ball) >= getHeight(window))
            {
                velocity_y = 0;
                velocity_x = 0;
                lives--;
                points = 0;
                updateScoreboard(window, label, points);
                bricks = COLS*ROWS;
                keepgoing = false;
            }
        }
    }
}

May someone can explain me why after I lost my first live, and then I click the mouse, nothing happen.

Thanks for your time.

2

You've got the right mindset, but think about this approach.

Initiate a flag for velocity, this will dictate if the ball is moving or not. Initially it is 0, and the ball is at rest in the center. When a click event is noticed, the flag turns to 1, which triggers an if statement, giving the ball velocity.

If the bottom is struck, turn the velocity flag to 0. At this stage, the ball would just stop moving. Pair this with another action, moving the ball back to the center. Now, as the ball strikes the bottom, it stops moving and is transported back to the center. Only clicking the mouse again can turn the velocity flag back to 1, restarting movement.

1
  • 1
    Thanks for your quick response, you're totally right, after the first ball lost, my program started a new ball but like this one was already at the bottom, velocity got null again and again... I would never saw!! – CharlesD89 Oct 18 '15 at 2:11

You must log in to answer this question.

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