← back to projects

Pong

Python turtle graphics first project

My first ever coding project: the classic two-player Pong, written in Python with the built-in turtle graphics library. It's where I first learned what a game loop, coordinates and collision detection actually are.

My role: a solo project.

Play it: browser port of main.py playable

Player A: W S  ·  Player B: ↑ ↓  ·  On a phone: drag on the field

Same rules and numbers as my original Python code: field size, paddle positions, ball speed, bounce and scoring lines, and 20-unit paddle moves. The computer opponent, Start/Pause and touch controls were added for this web version.

How it works

Game loop. Every step moves the ball by dx and dy. Hitting the top or bottom edge flips dy, so the ball bounces.

Scoring. If the ball gets past a paddle, the other player scores and the ball restarts in the middle, heading the other way.

Collision. When the ball reaches a paddle's x position and is within 40 units of its centre, dx flips and it bounces back.

What I'd do differently now

Looking back at my first project, a few things stand out:

Speed depended on the computer. The loop ran as fast as the machine allowed, so the ball was faster on a faster laptop. Now I'd tie movement to elapsed time.

Paddles could leave the screen. Nothing stopped them moving past the top or bottom edge.

The same serve every time. The ball always restarts at the same angle, so rallies get predictable. A random serve angle would fix it.

Repeated code. Paddle A and B were built from copied code. Today I'd write one Paddle class and create two of them.