M-Husnain-Ali/Pong-Multithreaded-Game
Pong Multithreaded Linux C++ Game is a modern take on the classic Pong game, utilizing advanced OS concepts. This game features multithreading with separate threads for ball and paddle control, real-time scoring, and engaging graphics using SDL2. Two human players can enjoy competitive gameplay with responsive controls and a seamless experience
๐ฎ Pong Multithreaded Game - OS Project
A multithreaded implementation of the classic Pong game, developed as an Operating Systems project to demonstrate practical applications of OS concepts like process management, threading, and synchronization.
Author: Muhammad Husnain Ali
๐ Table of Contents
- Overview
- Requirements
- Installation
- Features
- Game Controls
- Game Rules
- Project Structure
- OS Concepts Demonstrated
- Contributing
- License
๐ฏ Overview
This project is a modern implementation of the classic Pong game, specifically designed to demonstrate key Operating System concepts. The game utilizes multithreading for smooth performance and responsive controls, showcasing practical applications of process management and thread synchronization in a real-time gaming environment.
๐ป Requirements
- Ubuntu Linux (Tested on Virtual Machine)
- Virtual Machine Software (VirtualBox/VMware recommended)
- C++ Compiler (GCC/G++)
- SDL2 Library and Development Files
- SDL2_ttf Library for Text Rendering
- pthread Library
- Minimum VM Configuration:
- 2GB RAM
- 2 CPU Cores
- 800x600 minimum resolution
- Guest Additions installed for better performance
๐ Installation & Setup
-
Set Up Ubuntu Virtual Machine
# First ensure your Virtual Machine is properly configured # Install Guest Additions for better performance sudo apt-get update sudo apt-get install virtualbox-guest-utils virtualbox-guest-x11
-
Install Dependencies
sudo apt-get update sudo apt-get install build-essential sudo apt-get install libsdl2-dev libsdl2-ttf-dev
-
Clone the Repository
git clone https://github.com/M-Husnain-Ali/Pong-Multithreaded-Game.git cd Pong-Multithreaded-Game -
Compile the Game
g++ pong.cpp -o pong -lSDL2 -lSDL2_ttf -pthread
-
Run the Game
./pong
โจ Features
- Multithreaded Architecture:
- Separate thread for ball movement
- Independent threads for each paddle
- Smooth gameplay experience
- Demonstrates OS thread management
- Real-time Physics:
- Accurate ball collision detection
- Responsive paddle movement
- Dynamic ball speed
- Score System:
- Real-time score display
- Center-aligned score positioning
- Automatic score updates
- Graphics:
- SDL2 hardware-accelerated rendering
- Clean and minimalist design
- Smooth animations
๐ฎ Game Controls
| Player | Controls | Action |
|---|---|---|
| Player 1 | W |
Move Paddle Up |
| Player 1 | S |
Move Paddle Down |
| Player 2 | โ |
Move Paddle Up |
| Player 2 | โ |
Move Paddle Down |
| Any | ESC |
Quit Game |
๐ Game Rules
-
Scoring:
- Score points when the ball passes opponent's paddle
- Game continues until players decide to quit
- Scores are displayed at the top of the screen
-
Gameplay:
- Ball speed remains constant
- Paddles move at a fixed speed
- Ball bounces off paddles and walls
- Ball resets to center after scoring
๐ Project Structure
pong-multithreaded/
โโโ pong.cpp # Main game implementation with threading
โโโ README.md # Project documentation
โโโ .git/ # Git repository data
๐ง OS Concepts Demonstrated
-
Process Management:
- Main game process handling
- Resource allocation and management
- Process synchronization
-
Threading Model:
- pthread implementation
- Thread creation and management
- Thread synchronization
- Race condition prevention
- Mutex implementation (implicit in SDL)
-
Memory Management:
- Shared memory between threads
- Resource cleanup and memory deallocation
- Buffer management for rendering
-
I/O Handling:
- Event-driven input processing
- Real-time user input handling
- Graphics buffer management
๐ค Contributing
- Fork the repository
- Create a new branch
- Make your changes
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Operating Systems Course Project