Pong in 25 lines code
This is the Blitz Basic source code for my single player version of Pong using just 25 lines without any 'cheating' (each line contains only one command). The game doesn't include sound but does have a scoring routine, a ball that gets faster as the point progresses, simple AI and real physics (albeit with a random element thrown in so that it isn't too predictable).
This is hosted on GitHub and embedded here.
To anybody familiar with Blitz Basic there shouldn't be anything above that causes you too much trouble. No external media is required so the code can be compiled and run as is.
The variables used should be fairly self explanatory but if you are unsure the following may help:
- P1y and P2y are the y co-ordinates corresponding to the top of the player bats.
- P1score and P2score are the player scores
- Bx and By are the x and y coordinates of the ball
- Bangle is the angle that the ball is travelling in measured from the horizontal (in the range -180 to 180)
- start is the time in milliseconds that the current point started