First, we will create a new method called ControlPlayer
.
1. This method will check for keyboard input and move the player paddle according to it. Add this method to the
pongo
class.Method ControlPlayer:Int()
2. When the player presses the up key, we are moving the player paddle by 5 pixels, upwards.
If KeyDown(KEY_UP) Then 'check if UP key is pressed pY -= 5.0 'subtract 5 pixel from Y position
As the paddle should stop at the top, we check if its Y position is less than 25 pixels away (paddle height is equal to 50 pixel) and set its Y position back to 25 pixels.
If pY < 25.0 Then pY = 25.0 'Check against top wall Endif:Now we check if the DOWN key is pressed and move the paddle accordingly. Again, we check if it reaches the bottom wall. If KeyDown(KEY_DOWN) Then 'Check if DOWN key is pressed pY += 5.0 'Add 5 pixels to Y position If pY > 455.0 Then pY = 455.0 'Check against bottom wall Endif
3. Now, close the method.
Return True End
4. To actually...