Moving the ball is as simple as moving the paddles, as you will see.
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.
If bY < 10.0 then bY = 10.0 'Set the Y position back to 10.0 bdY *= -1 'Inverse the balls Y speed Endif
If bY > 470.0 then bY = 470.0 'Set the Y position back to 470.0 bdY *= -1 'Inverse the balls Y speed Endif
If bX < 5.0 then bX = 5.0 'Set the X position back to 5.0 bdX *= -1 'Inverse the balls X speed pPoints += 1 'Add 1 to the player's points
gameMode
to GameOver
. After that, close the If
statement.If pPoints >= 10 then gameMode = 2 Print (ePoints + ":" + pPoints) Endif
If bX > 635.0 then bX = 635.0 'Set the X position back to 635.0 bdX *= -1 'Inverse the balls X speed ePoints += 1 'Add 1 to the enemies points
gameMode
to GameOver
. After that, close the If
statement. And close the method.If ePoints >= 10 then gameMode = 2 Print (ePoints + ":" + pPoints) Endif End
UpdateBall
into the UpdateGame
method.ControlEnemies() 'Control the enemy UpdateBall() 'Update the ball's position Return True
If you need a pre-made source file for the next steps, Pongo_07.Monkey
can help you there.