Skip to content
/ pong- Public

The implementation of the two player ping pong game using pygame

Notifications You must be signed in to change notification settings

Sauceg/pong-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

### 1. Pygame Initialization and Setup
- Pygame modules are initialized, a display window is created, and the title of the window is set.
- The `main()` function initializes the game, creates a `Game` object, and starts the main game loop.

### 2. `Game` Class
- Represents the main game object.
- Manages game-specific attributes such as paddle, ball, score, and game state.
- The `play()` method is the main game loop where events are handled, the game is drawn, and updates are made.
- `handle_events()` method handles user events such as key presses.
- `handle_key_down()` and `handle_key_up()` methods handle key presses and releases, respectively.
- `draw()` method draws all game objects, including paddles, ball, and scores.
- `update()` method updates the game state, including paddle movement, ball movement, and score.
- `decide_continue()` method checks if the game should continue based on the score.

### 3. `Paddle` Class
- Represents the paddle in the game.
- Manages attributes such as position, dimensions, color, and movement.
- `draw()` method draws the paddle on the game surface.
- `set_vertical_velocity()` method sets the vertical velocity of the paddle.
- `move()` method moves the paddle vertically within the window boundaries.

### 4. `Ball` Class
- Represents the ball in the game.
- Manages attributes such as color, radius, center position, velocity, surface, and collision with paddles.
- `draw()` method draws the ball on the game surface.
- `move()` method moves the ball within the window boundaries and handles collisions with paddles.
- `collidepoint()` method checks if the ball collides with the left or right paddle.

### 5. Functionality
- Players can control the left paddle using the 'q' and 'a' keys.
- Players can control the right paddle using the 'p' and 'l' keys.
- The game ends when either player reaches a score of 11.
- The ball bounces off the top and bottom edges of the window.
- Scores for both players are displayed on the window.

Your code provides a basic implementation of the classic Pong game. You can further enhance it by adding features like sound effects, ball acceleration, and a more sophisticated AI opponent. Additionally, you may consider improving the code structure and adding comments for clarity and maintainability.

About

The implementation of the two player ping pong game using pygame

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages