-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added New Game: Ping pong #5036
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# **Ping_Pong** | ||
|
||
--- | ||
|
||
<br> | ||
|
||
## **Description 📃** | ||
|
||
- Dive into the classic game of Ping Pong with our interactive web-based version, designed using HTML, CSS, and JavaScript. This game features a straightforward and intuitive interface where players can enjoy a fast-paced, two-player experience. | ||
|
||
|
||
|
||
## **Functionalities 🎮** | ||
|
||
The game simulates a realistic ping pong match with smooth paddle and ball physics, offering an engaging experience that mimics the feel of playing on a physical table. | ||
|
||
<br> | ||
|
||
## **How to play? 🕹️** | ||
|
||
1. Start the game. | ||
2. Player1 uses the AWSD keys to control is paddle while Player2 uses up,down,left,right keys to control his paddle | ||
3. Both players need to defend their goals and score in other's goal. | ||
4. The player with the most points wins. | ||
|
||
|
||
<br> | ||
|
||
## **Screenshots 📸** | ||
|
||
![image](https://github.com/AaryanManghnani/GameZone/blob/Ping_Pong/assets/images/Ping_Pong.png) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Ping Pong Game</title> | ||
<link rel="stylesheet" type="text/css" href="./style.css"> | ||
</head> | ||
|
||
<body> | ||
<div id="game"> | ||
<div id="board"> | ||
<div class="divider"></div> | ||
</div> | ||
<div id="paddle-left"></div> | ||
<div id="paddle-right"></div> | ||
<div id="ball"></div> | ||
</div> | ||
<script src="./script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var ball = document.getElementById("ball"); | ||
var paddleLeft = document.getElementById("paddle-left"); | ||
var paddleRight = document.getElementById("paddle-right"); | ||
var game = document.getElementById("game"); | ||
var ballX = 250; | ||
var ballY = 150; | ||
var xSpeed = 2; | ||
var ySpeed = 2; | ||
var ballSpeed = 10; | ||
var paddleSpeed = 20; | ||
var paddleTopBoundary = 0; | ||
var paddleBottomBoundary = game.clientHeight - paddleLeft.clientHeight; | ||
var paddleLeftInitialX = 0; | ||
var paddleLeftInitialY = (game.clientHeight - paddleLeft.clientHeight) / 2; | ||
var paddleRightInitialX = game.clientWidth - paddleRight.clientWidth; | ||
var paddleRightInitialY = (game.clientHeight - paddleRight.clientHeight) / 2; | ||
|
||
|
||
paddleLeft.style.left = paddleLeftInitialX + "px"; | ||
paddleLeft.style.top = paddleLeftInitialY + "px"; | ||
paddleRight.style.left = paddleRightInitialX + "px"; | ||
paddleRight.style.top = paddleRightInitialY + "px"; | ||
|
||
|
||
|
||
document.addEventListener("keydown", function (e) { | ||
if (e.keyCode === 38) { | ||
var top = paddleRight.offsetTop; | ||
if (top > paddleTopBoundary) { | ||
paddleRight.style.top = top - paddleSpeed + "px"; | ||
} | ||
} else if (e.keyCode === 40) { | ||
var top = paddleRight.offsetTop; | ||
if (top < paddleBottomBoundary) { | ||
paddleRight.style.top = top + paddleSpeed + "px"; | ||
} | ||
} else if (e.keyCode === 87) { | ||
var top = paddleLeft.offsetTop; | ||
if (top > paddleTopBoundary) { | ||
paddleLeft.style.top = top - paddleSpeed + "px"; | ||
} | ||
} else if (e.keyCode === 83) { | ||
var top = paddleLeft.offsetTop; | ||
if (top < paddleBottomBoundary) { | ||
paddleLeft.style.top = top + paddleSpeed + "px"; | ||
} | ||
} | ||
}); | ||
|
||
|
||
function moveBall() { | ||
ballX += xSpeed; | ||
ballY += ySpeed; | ||
|
||
if (ballX + 10 > game.clientWidth || ballX < 0) { | ||
xSpeed = -xSpeed; | ||
} | ||
|
||
if (ballY + 10 > game.clientHeight || ballY < 0) { | ||
ySpeed = -ySpeed; | ||
} | ||
|
||
if (ballX < paddleLeft.clientWidth && ballY > paddleLeft.offsetTop && ballY < paddleLeft.offsetTop + paddleLeft.clientHeight) { | ||
xSpeed = -xSpeed; | ||
} | ||
|
||
if (ballX + 10 > game.clientWidth - paddleRight.clientWidth && ballY > paddleRight.offsetTop && ballY < paddleRight.offsetTop + paddleRight.clientHeight) { | ||
xSpeed = -xSpeed; | ||
} | ||
|
||
ball.style.left = ballX + "px"; | ||
ball.style.top = ballY + "px"; | ||
|
||
setTimeout(moveBall, ballSpeed); | ||
} | ||
|
||
moveBall(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#game { | ||
width: 500px; | ||
height: 300px; | ||
margin: 50px auto; | ||
border: 1px solid black; | ||
position: relative; | ||
} | ||
|
||
.divider { | ||
width: 2px; | ||
height: 100%; | ||
position: absolute; | ||
left: 50%; | ||
background: black; | ||
transform: translateX(-50%); | ||
} | ||
|
||
|
||
#board { | ||
width: 100%; | ||
height: 100%; | ||
background: white; | ||
} | ||
|
||
#paddle-left, #paddle-right { | ||
width: 10px; | ||
height: 50px; | ||
position: absolute; | ||
background: black; | ||
} | ||
|
||
#paddle-left { | ||
left: 0; | ||
} | ||
|
||
#paddle-right { | ||
right: 0; | ||
} | ||
|
||
|
||
#ball { | ||
width: 10px; | ||
height: 10px; | ||
position: absolute; | ||
background: red; | ||
border-radius: 50%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chane name of the repo to kunjgit instead of your repo name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.