O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — drawing the ball and the paddles

The next thing we want to draw is the ball and the paddles. Follow the ensuing steps:

  1. For this, we will add a single DrawCircle command and some DrawRect commands to the OnRender method.
    Method OnRender:Int()
    Cls 'Clear the canvas each frame
    DrawPlayField() 'Draw the play field
    DrawRect(pX, pY-30, 5, 60) 'Draw the player paddle
    DrawRect(eX[0], eY[0]-30, 5, 60) 'Draw the enemy paddle #1
    DrawRect(eX[1], eY[1]-30, 5, 60) 'Draw the enemy paddle #2
    DrawCircle(bX, bY, 5) 'Draw the ball with a radius of 5
    Return True
    
  2. Better "save" than sorry. So, you should save this script under a name of your choice and test it again.
  3. For the rest of the process, you can use the pre-built script Pongo_04.Monkey. Does ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required