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 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()
2. 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
3. Like before, save your script and test it...