From a08b1e8366a97167751208461ff95926f8d84776 Mon Sep 17 00:00:00 2001 From: Aaryan Manghnani <108581214+AaryanManghnani@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:51:17 +0530 Subject: [PATCH 1/5] Add files via upload --- assets/images/Ping_Pong.png | Bin 0 -> 2766 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/images/Ping_Pong.png diff --git a/assets/images/Ping_Pong.png b/assets/images/Ping_Pong.png new file mode 100644 index 0000000000000000000000000000000000000000..d14564ffddbd224e53394a7d42af5061830ea4f6 GIT binary patch literal 2766 zcmeAS@N?(olHy`uVBq!ia0y~yVEWC#z<88{4JeW$X~qYn7>k44ofy`glX(f`u%tWs zIx;Y9?C1WI$O`0h7I;J!GcX91fH32|H2De!2CigJ7srr_xVN_#_KA2)G+cbOTHu4# zi`WYag(@FXCOnw1ATj*2l|sQ`vD;6iX3X>xIBWh~W$vn1|E{j^zoOG_&CI}X;%9y= zBSVA4Mt%l{z$AGFhDAs07#LhSYZ(|ign%v-Q2oZppy2g}nZaSo4R(eGjX|Ms+TppS z=Q&SrT4T+?@XvJmjJ-+q&62Ij;bY{x|^U=Edrq@?K4;tiIpKAW5eu20D;=_U)Ulc3~ z)6aJLU@JB06?B{Z^Y8b4{PI$wU#@qf&iB_g=f5*B%yE6QS^xh2{*QltO019X|M>H> z#QlAD_s<8(e*Qg&nc;!P#`F93R2UvR-v9a`|FiFw>_Up%AJ3DjRIcA0!iH+y${`@k2w-e5@so9ZtZcC{g z!-GQ|wcj3pd|X<*Z0%HAn^$}c2X4|U$Ol*TJc4|^;%Pzp-Qq)=bY25fN&Q*XwDsUt(lBXo dct|~FpV_~uNG~}-2-pT?@O1TaS?83{1OU&sTzUWi literal 0 HcmV?d00001 From 52ab08dbc19bb34e48aed3a4af37cc9279a067b6 Mon Sep 17 00:00:00 2001 From: Aaryan Manghnani <108581214+AaryanManghnani@users.noreply.github.com> Date: Tue, 30 Jul 2024 19:52:19 +0530 Subject: [PATCH 2/5] Add files via upload --- Games/Ping_Pong/index.html | 21 ++++++++++ Games/Ping_Pong/script.js | 78 ++++++++++++++++++++++++++++++++++++++ Games/Ping_Pong/style.css | 47 +++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 Games/Ping_Pong/index.html create mode 100644 Games/Ping_Pong/script.js create mode 100644 Games/Ping_Pong/style.css diff --git a/Games/Ping_Pong/index.html b/Games/Ping_Pong/index.html new file mode 100644 index 0000000000..523bcec9e3 --- /dev/null +++ b/Games/Ping_Pong/index.html @@ -0,0 +1,21 @@ + + + + + Ping Pong Game + + + + +
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/Games/Ping_Pong/script.js b/Games/Ping_Pong/script.js new file mode 100644 index 0000000000..f5646b3982 --- /dev/null +++ b/Games/Ping_Pong/script.js @@ -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(); + diff --git a/Games/Ping_Pong/style.css b/Games/Ping_Pong/style.css new file mode 100644 index 0000000000..821126c4b0 --- /dev/null +++ b/Games/Ping_Pong/style.css @@ -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%; + } \ No newline at end of file From 3aa1910a698fc8f2a7f18d6c92a3a6937bc638c3 Mon Sep 17 00:00:00 2001 From: Aaryan Manghnani <108581214+AaryanManghnani@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:04:11 +0530 Subject: [PATCH 3/5] Create README.md --- Games/Ping_Pong/README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Games/Ping_Pong/README.md diff --git a/Games/Ping_Pong/README.md b/Games/Ping_Pong/README.md new file mode 100644 index 0000000000..fdf3f789f8 --- /dev/null +++ b/Games/Ping_Pong/README.md @@ -0,0 +1,34 @@ +# **Ping_Pong** + +--- + +
+ +## **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. + +
+ +## **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. + + +
+ +## **Screenshots 📸** + +![image](https://github.com/AaryanManghnani/GameZone/blob/Ping_Pong/assets/images/Ping_Pong.png) + + + From 07eddcd96e5ef4e5443b1d8a9dbcd42e0819bbc3 Mon Sep 17 00:00:00 2001 From: Aaryan Manghnani <108581214+AaryanManghnani@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:05:37 +0530 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62da34b64f..ef94253895 100644 --- a/README.md +++ b/README.md @@ -822,7 +822,7 @@ This repository also provides one such platforms where contributers come over an | [Cosmic_Blast](https://github.com/kunjgit/GameZone/tree/main/Games/Cosmic_Blast) | |[Mole](https://github.com/taneeshaa15/GameZone/tree/main/Games/Mole)| |[Pottery-Game](https://github.com/kunjgit/GameZone/tree/main/Games/Pottery-Game)| - +|[Ping_Pong](https://github.com/AaryanManghnani/GameZone/tree/Ping_Pong/Games/Ping_Pong) | [Typing_Test](https://github.com/kunjgit/GameZone/tree/main/Games/Typing_Test) | |[Wheel_of_Fortunes](https://github.com/Saipradyumnagoud/GameZone/tree/main/Games/Wheel_of_Fortunes)| From 3f4dc92e5535c2833fc7b2781927e8154301e633 Mon Sep 17 00:00:00 2001 From: Aaryan Manghnani <108581214+AaryanManghnani@users.noreply.github.com> Date: Wed, 31 Jul 2024 19:17:11 +0530 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef94253895..2f2b53e55b 100644 --- a/README.md +++ b/README.md @@ -822,7 +822,7 @@ This repository also provides one such platforms where contributers come over an | [Cosmic_Blast](https://github.com/kunjgit/GameZone/tree/main/Games/Cosmic_Blast) | |[Mole](https://github.com/taneeshaa15/GameZone/tree/main/Games/Mole)| |[Pottery-Game](https://github.com/kunjgit/GameZone/tree/main/Games/Pottery-Game)| -|[Ping_Pong](https://github.com/AaryanManghnani/GameZone/tree/Ping_Pong/Games/Ping_Pong) +|[Ping_Pong](https://github.com/kunjgit/GameZone/tree/main/Games/Ping_Pong) | [Typing_Test](https://github.com/kunjgit/GameZone/tree/main/Games/Typing_Test) | |[Wheel_of_Fortunes](https://github.com/Saipradyumnagoud/GameZone/tree/main/Games/Wheel_of_Fortunes)|