A simple Pong game built with Pygame. It features a main menu, configuration screen, single-player (AI) and two-player modes, score/round tracking, and sound effects.
- Entry point:
pong.py
- Core classes:
player.Player
,player.AutoPlayer
,ball.Ball
,button.Button
- Single-player mode (play against an AI) and two-player mode
- Menu and configuration screens
- Configurable match: points per round and rounds to win
- Sound effects and basic visuals
- Python 3.8+
- Pygame (
pip install pygame
)
# Optional: create and activate a virtual environment
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
# Install dependency
pip install pygame
python pong.py
This starts the app and opens the main menu from pong.menu
. Use the mouse to select options.
- 1 Player Mode: You control the left paddle; the right paddle is AI (see
player.AutoPlayer
). - 2 Players Mode: Both paddles are controlled by players.
Controls:
- Player 1 (left): W (up), S (down)
- Player 2 (right): Up Arrow (up), Down Arrow (down)
From the configuration menu (opened via main menu), you can set:
- ROUNDS: Number of rounds needed to win the match
- POINTS: Points needed to win a round
A player wins a round upon reaching the selected points. The match ends when a player wins the selected number of rounds and the game returns to the main menu via pong.main
.
-
Game entry and loop orchestration:
pong.main
: Initializes Pygame, window, mixer, and opens the menu.pong.menu
: Main menu UI usingbutton.Button
.pong.configuration_menu
: Lets you select ROUNDS and POINTS, then starts the game.pong.main_game
: Sets up paddles and ball, runs the gameplay loop.pong.draw_on_screen
: Renders paddles, ball, scores, rounds, and midfield line.pong.key_movements
: Handles keyboard input and AI movement.pong.render_text
: Utility to render text.
-
Game objects:
player.Player
: Paddle controlled by keyboard.player.AutoPlayer
: AI-controlled paddle with simple ball prediction.ball.Ball
: Ball physics and collisions:
-
UI:
button.Button
: Reusable text-button with hover sound and state.
All assets live under assets/
:
- Images:
player1.png
,player2.png
,background.png
,moon.png
- Fonts:
font.ttf
- Sounds:
button.ogg
,player_collision.mp3
,wall_collision.mp3
,score.mp3
Note: On case-sensitive filesystems the game uses the lowercase background file: assets/background.png
.
- Default window size: 800x600 (see
pong.main
). - The main loop targets 60 FPS via
pygame.time.Clock()
inpong.main_game
.
- If audio initialization fails (e.g., no audio device), Pygame mixer may raise errors. As a workaround on headless systems:
- Set an SDL audio driver (e.g.,
SDL_AUDIODRIVER=dummy
) before running.
- Set an SDL audio driver (e.g.,
- Ensure all files in the
assets/
directory are present and readable.
No license specified.