Moving the ball is as simple as moving the paddles, as you will see.
1. For updating the ball's position, you need to create a new method called
UpdateBall
. At first, we will update the ball's X and Y position:Method UpdateBall:Int() bX += bdX 'Add the X speed of the ball to its X position bY += bdY 'Add the Y speed of the ball to its Y position
We could end here, but then the ball would not bounce of the walls and would just disappear in nowhere land.
2. Add a check if the ball hits the top wall and reacts to it.
If bY < 10.0 then bY = 10.0 'Set the Y position back to 10.0 bdY *= -1 'Inverse the balls Y speed Endif
3. Next, check if the ball hits the bottom wall and, again, reacts to it.
If bY > 470.0 then bY = 470.0 'Set the Y position back to 470.0 bdY *= -1 'Inverse the balls Y speed Endif
4. Now, check against the left wall. If it hits it, add a point to the player's points.
If bX < 5.0 then bX = 5.0 'Set the X position back to 5.0 bdX *= ...