Game Programming in Pascal - Pong

Why do these programming talk-throughs?

In these programming talk-throughs you will learn how to create your very own Pong game using the FreePascal compiler and Lazarus integrated development environment (IDE). You will also learn many useful programming concepts that can be applied to any computer language.

History of Pong

The history of Pong, and a web implementation in Adobe Flash can be found at


Before you get started, you will need to install the FreePascal compiler and Lazarus Integrated Development Environment. Instructions to do this are here.

This is what we will be building in these talk-throughs: Pong working program for Windows.

Pong sound files (*.wav files) used in talk-through #19: Pong sound files

Pong source code (FreePascal) you will have written by the end of the talk-throughs: Pong source code.

Talk-through #1 - Create the Empty Application

  • Create a directory to store the game
  • Create an empty application
  • Save the application & main form with good name
  • Run the application to check all is working

Talk-through #2 - Set the Look and Feel

  • Make main form black
  • Set the size
  • Set the position on the screen
  • Set the border - none

Talk-through #3 - Catching the Escape Key to Exit

  •  Close game when ESC key is hit

Talk-through #4 - Draw a Ball (Rectangle) on the Screen

  •  Draw the ball

Talk-through #5 - Move a Ball (Rectangle) on the Screen

  •  Move the ball on the screen

Talk-through #6 - Simplify the Move Ball Code

  •  Simplify the Move Ball code

Talk-through #7 - Move the Ball in Response to the Keyboard

  • Make ball respond to user commands
  • Move Right - L key
  • Move Left - J key
  • Move Up - I key
  • Move Down - M key

Talk-through #8 - Computer to move ball around the screen

Talk-through #9 - Bounce ball at edge of the screen

Talk-through #10 - Move the ball on an angle

Talk-through #11 - Bounce the ball when its moving on an angle

Talk-through #12 - Add bats to game and move them in response to key board

Talk-through #13 - Limit the bats to the screen

  • Limit the bats to the screen
  • Tidy up code by using constants

Talk-through #14 - Bounce the ball on the bats

Talk-through #15 - Keep score

  • Declare variables to store the score
  • Initialize variables when game starts
  • Detect a miss and inc the correct score
  • Display the score on the screen
  • When score reaches x, announce the winner

Talk-through #16 - Draw some nets

Talk-through #17 - Ball damaging bat, net & score

Talk-through #18 - Instruction on the screen

Talk-through #19 - Sounds when the ball bounces

 Talk-through #20 - Tidy up the code

  • Fix the pause when the ball bounces
  • Make the game harder to play
  • Smaller game area
  • Make bats smaller
  • Make the ball faster

Toggle menu