0

I'm working on breakout and I am on step #6 where I have the bricks and paddle and now I'm working on the ball. However, after I got the ball to move, my paddle no longer moves and I have no idea why. I have copied a snippet of my code below; any insight would be most appreciated!

Thanks!

// keep playing until game over
while (lives > 0 && bricks > 0)
{
    // TODO
    // initial velocity
    double velocity_y = 2.0;
    double velocity_x = 2.0;

    // bounce forever
    while (true)
    {
        // move ball along x-axis
        move(ball, velocity_x, velocity_y);

        // bounce off bottom of window
        if (getY(ball) + getHeight(ball) 
        >= getHeight(window))
        {
            velocity_y = -velocity_y;
        }

        // bounce off top of window
        if (getY(ball) <= 0)
        {
            velocity_y = -velocity_y;
        }

        // bounce of right of window
        if (getX(ball) + getWidth(ball)
        >= getWidth(window))
        {
            velocity_x = -velocity_x;
        }

        // bounce of left of window
        else if (getX(ball) <= 0)
        {
            velocity_x = -velocity_x;
        } 

        // linger before moving again
        pause(10);
    }

    // PADDLE: follows mouse forever
    while (true)
    {
        // check for mouse event
        GEvent event = getNextEvent(MOUSE_EVENT);

        // if we heard one
        if (event != NULL)
        {
            // if the event was movement
            if (getEventType(event) == MOUSE_MOVED)
            {
                // ensure paddle follows top cursor
                double x = 
                getX(event) - getWidth(paddle) / 2;
                double y = HEIGHT - Hpaddle - 5;
                setLocation(paddle, x, y);
            }
        }
    }
3

look at your 2nd while loop that moves the ball, think about when your code will exit that and move on to the part of the code that moves the paddle

| improve this answer | |
  • Your answer just saved me hours of work. Thanks! – peachykeen Nov 19 '15 at 4:00

You must log in to answer this question.

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