A classic Pong game built with HTML, CSS, and JavaScript. Play against the computer AI in this nostalgic arcade experience with modern styling and smooth gameplay.
- Player vs Computer: Challenge the AI opponent with adaptive difficulty
- Mouse & Keyboard Control: Control your paddle with mouse movement or arrow keys
- Real-time Scoring: Keep track of scores for both player and computer
- Physics-Based Collision:
- Ball bounces off walls realistically
- Paddle collisions with spin mechanics
- Smooth ball trajectory calculations
- Neon Cyberpunk Design: Modern visual effects with glowing elements
- Responsive Gameplay: Smooth 60 FPS animation using RequestAnimationFrame
- Easy Reset: Reset the game with a single button click
- Open the Game: Simply open
index.htmlin your web browser - Control Your Paddle:
- Move your mouse up/down over the game canvas, OR
- Use arrow keys (↑/↓) to move the left paddle
- Objective:
- Prevent the ball from reaching the left edge (your side)
- Get the ball past the computer's paddle to score
- Scoring: Each time the ball goes out of bounds, the opposite player scores a point
- Reset: Click the "Reset Game" button to start over with scores at 0-0
| Action | Input |
|---|---|
| Move Paddle Up | Mouse Move Up or ⬆️ Arrow Key |
| Move Paddle Down | Mouse Move Down or ⬇️ Arrow Key |
| Reset Game | Click "Reset Game" Button |
- Left Paddle (Green): Controlled by the player
- Right Paddle (Green): Controlled by the computer AI
- Ball (Magenta): Bounces around the court
- Center Line: Divides the court
- Scoreboard: Displays current scores
The computer opponent has an adaptive difficulty level set at 0.8x, making it challenging but beatable. The AI:
- Tracks the ball's position
- Predicts ball movement
- Moves smoothly to intercept
- Can be beaten with skilled gameplay
| Specification | Value |
|---|---|
| Canvas Size | 800x400 pixels |
| Paddle Dimensions | 10x80 pixels |
| Ball Size | 8px radius |
| Player Paddle Speed | 6 pixels/frame |
| Computer Paddle Speed | 4.5 pixels/frame |
| Ball Initial Speed | 5 pixels/frame |
- Any modern web browser (Chrome, Firefox, Safari, Edge, etc.)
- No installation or dependencies required!
- Clone or download this repository
- Open
index.htmlin your web browser - Start playing!
pong-game/
├── index.html # Complete game file (HTML, CSS, and JavaScript)
└── README.md # This file
- Use Mouse Control: Mouse movement provides smoother, more responsive control
- Predict Ball Trajectory: Anticipate where the ball will go
- Use the Edges: Position your paddle at the edges to cover more area
- Add Spin: Hit the ball at different paddle heights to change its trajectory
- Stay Alert: Keep your paddle moving to react quickly
- HTML5: Canvas API for game rendering
- CSS3: Styling with gradients and shadows
- JavaScript (ES6): Game logic, physics, and AI
update(): Updates game state each framedraw(): Renders all game elementsgameLoop(): Main game loop using RequestAnimationFrameresetBall(): Resets ball to center with random directionresetGame(): Resets entire game state
- Velocity-based movement
- Collision detection using AABB (Axis-Aligned Bounding Box)
- Spin mechanics based on paddle position
- Ball trajectory prediction for AI
Possible improvements for future versions:
- Sound effects and background music
- Power-ups (speed boost, paddle size increase)
- Difficulty levels (Easy, Medium, Hard)
- Two-player mode (local multiplayer)
- Score history/statistics
- Mobile touch controls
- Particle effects
This project is open source and available for educational and personal use.
Feel free to fork this project and submit pull requests with improvements or new features!
For questions or suggestions, feel free to reach out.
Enjoy the game! 🎮✨