A polished 2-player Pong game built with Python's built-in turtle graphics module.
python(tested with Python 3.11 on Windows)- Standard library only:
turtlefor graphics, text, and keyboard inputtimefor frame pacing withsleep
No external packages are required.
pong_turtle.py: main game scriptREADME.md: project documentation
- Two-player local gameplay
- Live top scoreboard (
LeftandRight) - Dashed center line for a cleaner arena
- Pause and resume (
Space) - Restart (
R) - Quit (
Q) - Win condition: first player to reach
7points - Ball speed increases slightly after paddle hits
W: left paddle upS: left paddle downUp Arrow: right paddle upDown Arrow: right paddle downSpace: pause/resumeR: restart gameQ: quit game
From this folder:
python pong_turtle.py- Press
Spaceto start. - Ball crossing the right edge gives a point to Left.
- Ball crossing the left edge gives a point to Right.
- After each point, the ball resets to center.
- First player to
7points wins. - After win: press
Rto restart orQto quit.
pong_turtle.py defines constants for screen size, paddle limits, and win score:
WIDTH,HEIGHTPADDLE_LIMIT_TOP,PADDLE_LIMIT_BOTTOMWIN_SCORE
screen.tracer(0) enables manual frame updates for smoother animation.
make_paddle(x_pos)builds paddles with shared stylingleft_padandright_padare paddle turtlesballuses custom attributes:ball.dx: horizontal velocityball.dy: vertical velocityball.base_speed: reset speed after scoringdividerdraws the dashed middle line
score_writerprints current scoreinfo_writerprints controls, pause text, and winner textdraw_score()refreshes the score linedraw_info()refreshes the info line
State variables:
left_score,right_scoregame_pausedgame_over
Helper functions:
reset_ball(direction)resets position and serve directioncheck_winner()stops active play when a player reachesWIN_SCOREtoggle_pause(),restart_game(),quit_game()
The script uses screen.onkeypress(...) for controls:
- Left paddle:
w/s - Right paddle:
Up/Down - Game control:
space,r,q
Every frame:
- update screen
- wait
0.01s - skip movement if paused
- move ball by
dx/dy - bounce on top/bottom walls
- update score on left/right boundary crossing
- detect paddle collisions and increase speed slightly
- Change
WIN_SCOREfor match length - Change colors (
bgcolor, paddle/ball colors) - Change difficulty by editing:
ball.base_speed- collision multipliers (
1.05,1.02) - Add sound on hit/score (for example,
winsoundon Windows) - Add a simple AI for one paddle
- Check Python install:
python --version- If keys do not respond, click inside the game window once to focus it.
- If game feels too fast or too slow, change
time.sleep(0.01).