-5

Ball is not bouncing :(

while (lives > 0 && bricks > 0) { GRect rect = newGRect(162, 573, PWIDTH, PHEIGHT); // TODO add(window,rect); setFilled(rect,true); setColor(rect,"BLACK");

    GOval circle = newGOval(190,300,35,35);
    add(window,circle);
    setFilled(circle, true);
    setColor(circle,"RED");

    while(true)
    {
        GEvent event =getNextEvent(MOUSE_EVENT);
        if(event!=NULL)
        {
            if(getEventType(event)== MOUSE_MOVED)
            {
                double x = getX(event)-PWIDTH/2;
                setLocation(rect,x,573);
            }
        }
    }

    double velocity= 2.0;

    while(true)
    {
        move(circle, velocity, 0);

        if(getX(circle)+getWidth(circle)>=getWidth(window))
        {
            velocity=-velocity;
        }

        else if( getX(circle) <=0 )
        {
            velocity= -velocity;
        }
    }
}

1 Answer 1

0

You aren't moving the ball until the second infinite loop, but you're not leaving the first.

1
  • So, how to leave the first loop?
    – julio
    Aug 25, 2014 at 2:59

You must log in to answer this question.

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