Time for action — rendering the game field

Which elements will be rendered in the game?

  • The player paddle
  • Enemy paddle #1
  • Enemy paddle #2
  • The ball
  • A wall at the top
  • A wall at the bottom
  • A middle line

The last three elements can be grouped together as a background. So let us do just that:

  1. Now, insert the drawing routines for the background graphics. Between the OnUpdate method and the OnRender method, create a new method called DrawPlayField.
    Method OnUpdate:Int()
    Return True
    End
    Method DrawPlayField:Int()
    'Draw the top wall with a rectangle
    DrawRect(0,0,640,5)
    'Botton wall
    DrawRect(0,475,640,5)
    'Middle line, 13 pieces, each 10 pixel long
    For Local i:= 5 To 465 Step 20
    DrawRect(318,i,4,10)
    Next
    Return True
    End
    Method OnRender:Int()
    
  2. We need to modify the OnRender method now, so that the new DrawPlayField method can be called.
    Method OnRender:Int()
    Cls 'Clear the canvas each frame
    DrawPlayField() 'this call draws the background
    Return True
    End
    
  3. Like before, save your script and test it, to see if it runs fine. For going further with a pre-built script, you can use the Pongo_03.Monkey file. You should now see a screen that looks as follows:
Time for action — rendering the game field
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.195.225