Skip to main content

pset4 Breakout:bouncing Bouncing the ball upBall Up and downDown

i don't know why this code isI'm not makingsure how to make the ball bouncingbounce up and down!!.
Here's my code:

    while (lives > 0 && bricks > 0)
   {
            // moving paddle
  
            double velocity = 2.0; 
    
           move(ball, 0, velocity);
    
           if (getY(ball) <= 0)
           {
                   velocity = -velocity;
           }
           else if (getY(ball) + 2 * RADIUS >= getHeight(window))
           {
                        velocity = -velocity;
           }
     
            pause(10);
    
    
 }  
  

pset4:bouncing the ball up and down

i don't know why this code is not making the ball bouncing up and down!!

    while (lives > 0 && bricks > 0)
   {
            // moving paddle
  
            double velocity = 2.0; 
    
           move(ball,0,velocity);
    
           if (getY(ball)<= 0)
           {
                   velocity = -velocity;
           }
           else if (getY(ball) + 2 * RADIUS >= getHeight(window))
           {
                        velocity = -velocity;
           }
     
            pause(10);
    
    
 }  
  

Breakout: Bouncing the Ball Up and Down

I'm not sure how to make the ball bounce up and down.
Here's my code:

while (lives > 0 && bricks > 0)
{
    double velocity = 2.0; 
    
    move(ball, 0, velocity);
    
    if (getY(ball) <= 0)
    {
        velocity = -velocity;
    }
    else if (getY(ball) + 2 * RADIUS >= getHeight(window))
    {
        velocity = -velocity;
    }
     
    pause(10);
}  
  
Source Link

pset4:bouncing the ball up and down

i don't know why this code is not making the ball bouncing up and down!!

    while (lives > 0 && bricks > 0)
   {
            // moving paddle
  
            double velocity = 2.0; 
    
           move(ball,0,velocity);
    
           if (getY(ball)<= 0)
           {
                   velocity = -velocity;
           }
           else if (getY(ball) + 2 * RADIUS >= getHeight(window))
           {
                        velocity = -velocity;
           }
     
            pause(10);
    
    
 }