You gotta check for collision with the upper and lower walls. So let's say the upper wall is at y=upperY and the lower wall is at y = lowerY.
You got some radius of the ball, so you would check for collisions kinda like this:
//ball.position.y is the y coord of your ball
if(ball.position.y+ball.radius > upperY )
{
//Collision at (ball.position.x, upperY)
//calculate the bounce-off - we want to "reflect the ball from the wall
//To calculate reflection of a vector we need the normal of the wall
// However since the wall is parallel with the Ox basis vector, the normal of the wall
//is perpendicular to it, so for the upper wall we'll have upperNormal(0,-1)
//where ball.direction is the directional vector of the ball:
kFi = dot(ball.direction,upperNormal);
ball.direction.x = ball.direction.x - 2*kFi*upperNormal.x;
ball.direction.y = ball.direction.y - 2*kFi*upperNormal.y
}
//ball.position.y is the y coord of your ball
if(ball.position.y-ball.radius < lowerY )
{
//Collision at (ball.position.x, lowerY)
//calculate the bounce-off - we want to "reflect the ball from the wall
//To calculate reflection of a vector we need the normal of the wall
//However since the wall is parallel with the Ox basis vector, the normal of the wall
//is perpendicular to it, so for the lower wall we'll have lowerNormal(0,1)
//where ball.direction is the directional vector of the ball:
kFi = dot(ball.direction,lowerNormal);
ball.direction.x = ball.direction.x - 2*kFi*lowerNormal.x;
ball.direction.y = ball.direction.y - 2*kFi*lowerNormal.y
}
//And you use the new ball direction vector to move your ball once again
It's better if your ball.direction vector is normlized - then you can do this for movement:
//Each frame(if you got a game clock it's better)
ball.position = ball.position + ball.direction*ball.speed*deltaTime;
//Where you can calculate deltaTime each frame like so(not really a great way though):
deltaTime = fps*100/6;
//fps is frames per second
P.S. If something is not clear enough, tell me what it is and I'll elaborate more on it