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 — player paddle movement

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 ...

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