An open API service indexing awesome lists of open source software.

https://github.com/vermaharsha/pong-game

A simple Pong game using HTML5 Canvas and JavaScript with mouse control and AI opponent.
https://github.com/vermaharsha/pong-game

basic-trigonometry collision-detection coordinate-system-logic css game-loop html5-canvas javascript mouse-events object-oriented-javascript

Last synced: 4 months ago
JSON representation

A simple Pong game using HTML5 Canvas and JavaScript with mouse control and AI opponent.

Awesome Lists containing this project

README

          

# ๐ŸŽฎ Pong Game - JavaScript Canvas Edition

A classic Pong game recreation built using **HTML5 Canvas** and **Vanilla JavaScript**. The player controls the left paddle with mouse movement, while the right paddle is controlled by a basic AI. This project demonstrates game physics, paddle-ball collision logic, and responsive animation via `requestAnimationFrame`.

---

## ๐Ÿงฉ 1. Project Overview

This is a browser-based version of the iconic Pong game. It utilizes core JavaScript functionalities to create an interactive, real-time paddle-and-ball game with a simple AI opponent. This game runs entirely in the browser with no external game engine or library dependencies.

---

## โœจ 2. Features

* **Mouse-controlled Paddle:** Move the left paddle using your mouse.
* **AI Paddle:** Right paddle follows the ball with basic logic.
* **Ball Bounce Physics:** Reflects off paddles and walls with angle-based direction.
* **Scoring Logic:** Ball resets after missing either paddle (point scored).
* **Collision Spin Effect:** Collision point adds variation to ballโ€™s bounce angle.
* **Center Net:** Aesthetic dotted net in the center of the game.
* **Smooth Gameplay:** Uses `requestAnimationFrame()` for efficient rendering.

---

## ๐Ÿ› ๏ธ 3. Technologies Used

| Technology | Purpose |
| --------------- | ----------------------------- |
| HTML5 | Structure of canvas and page |
| CSS3 | Styling canvas and layout |
| JavaScript ES6 | Game logic and animations |
| HTML Canvas API | Drawing objects and animation |

---

## โš™๏ธ 4. Setup Instructions

Follow these steps to run the game locally:

1. **Clone the repository** or copy the files:

```bash
git clone https://github.com/yourusername/pong-game.git
cd pong-game
```

2. **File Structure:**

```
pong-game/
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ style.css
โ””โ”€โ”€ script.js
```

3. **Open `index.html` in your browser:**
Just double-click the file.

4. **Start Playing:**
Move your mouse up and down inside the canvas to control the left paddle.

---

---

## ๐Ÿ“ธ Screenshots

![Pong Game](https://github.com/user-attachments/assets/bae30489-f6ff-4a9c-84c2-2ab05de0adfa)

---

## ๐Ÿ™Œ Acknowledgments

* Inspired by the classic Pong arcade game (1972).
* Game logic and collision approach based on physics and math functions (`Math.sin`, `Math.PI`).
* HTML5 Canvas API for real-time rendering.