
上QQ阅读APP看书,第一时间看更新
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:
- Now, insert the drawing routines for the background graphics. Between the
OnUpdate
method and theOnRender
method, create a new method calledDrawPlayField
.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()
- We need to modify the
OnRender
method now, so that the newDrawPlayField
method can be called.Method OnRender:Int() Cls 'Clear the canvas each frame DrawPlayField() 'this call draws the background Return True End
- 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:
