TYBSc.
CS Ping Pong Mania
“Ping Pong Mania”
A Project Report
Submitted in partial fulfilment of the
Requirements of the award of the Degree of
BACHELOR OF SCIENCE (COMPUTER SCIENCE)
By
Anubhav Akhandh Pratap Singh
Roll No. : 96
Under the esteemed guidance of
Mrs. Jagruti raut
Designation
Professor
DEPARTMENT OF COMPUTER SCIENCE
Late Shri Vishnu Waman Thakur Charitable Trust’s
Bhaskar Waman Thakur College of Science,
Yashwant Keshav Patil College of Commerce,
Vidya Dayanand Patil College of Arts.
(Affiliated to University of Mumbai)
VIRAR, 401303
MAHARASHTRA
2023-2024
Roll No. : 96 Page |1
TYBSc.CS Ping Pong Mania
Late Shri Vishnu Waman Thakur Charitable Trust’s
Bhaskar Waman Thakur College of Science,
Yashwant Keshav Patil College of Commerce,
Vidya Dayanand Patil College of Arts.
(Affiliated to University of Mumbai)
Virar (W)-MAHARASHTRA-401303
DEPARTMENT OF INFORMATION TECHNOLOGY
CERTIFICATE
Roll No: 96 Exam Seat No. 2221183
This is to certify that the project entitled, “Ping Pong Mania", is bonafied work of Anubhav
Akhandh Pratap Singh bearing Seat. No: 2221183 submitted in partial fulfilment of the
requirements for the award of degree of BACHELOR OF SCIENCE in COPUTER SCIENCE
from University of Mumbai.
Internal Guide Head of Department
External Examiner
Date : College Seal
Roll No. : 96 Page |2
TYBSc.CS Ping Pong Mania
DECLARATION
I hereby- declare that the project entitled, “Ping Pong Mania” done at Viva College Virar
West, has not been in any case duplicated to submit to any other university for the award of
any degree. To the best of my knowledge other than me, no one has submitted to any other
university.
The project is done in partial fulfilment of the requirements for the award of degree of
BACHELOR OF SCIENCE (COMPUTER SCIENCE) to be submitted as final semester
project as part of our curriculum.
Anubhav Akhandh Pratap Singh
(Signature)
Roll No. : 96 Page |3
TYBSc.CS Ping Pong Mania
ACKNOWLEDGEMENT
I am very grateful to our Principal for providing us with an environment to complete
my project successfully.
I am deeply indebted to Prof. Jagruti Raut Head of C.S Department, VIVA
College who modelled us both technically and morally for achieving greater success in life.
I express our sincere thanks to all our lecturers, for their constant encouragement and
support throughout our course, especially for the useful suggestions given during the course
of the project period. I am grateful to my internal guide Prof. Jagruti Raut Lecturer, for
being instrumental in the completion of our project with her complete guidance.
We would like to thank our parent for providing us with all their support and
encouragement right from the project’s budding stage to its current maturity.
Above all we would like to thank the almighty for giving us courage and energy to
work day and night to make this project a grand success.
Roll No. : 96 Page |4
TYBSc.CS Ping Pong Mania
Table of Contents
Table of Contents ..................................................................................................................... 5
Chapter 1: Introduction .......................................................................................................... 7
1.1 Purpose ..................................................................... Error! Bookmark not defined.
1.2 Drawbacks ...................................................................................................................... 8
Chapter 2: Requirement ......................................................................................................... 9
2.1 Modules ........................................................................................................................... 9
2.2 Front End & Back End-Python .................................................................................. 10
2.4 Hardware ...................................................................................................................... 10
2.5 Software ........................................................................ Error! Bookmark not defined.
Chapter 3: System Design ..................................................................................................... 12
3.1 Gantt Chart................................................................................................................... 12
3.2 UML Diagrams ............................................................................................................. 13
3.3 Coding ........................................................................................................................... 15
3.4 Testing ........................................................................................................................... 17
3.5 Conclusion & References ............................................................................................. 19
Roll No. : 96 Page |5
TYBSc.CS Ping Pong Mania
SELF - ATTESTED PLAGARISM REPORT
Roll No. : 96 Page |6
TYBSc.CS Ping Pong Mania
Chapter 1: Introduction
The Ping Pong game is one of the earliest arcade games. It is table-tennis inspired
game featuring simple two dimensional graphics. In it, the player controls the paddle by
moving it vertically across the left or the right side of the screen. The objective is to eliminate
one of the opponent; each player earns points until the opponent fails to return the ball.
The aim of this project is to create a python-based application for Ping Pong Mania
using the cvzone and numpy library. It is also involves hand gesture.
My project is basically a ping pong game. Ping pong is a well-known computer game
that is similar to the table tennis. The two players in this game control the two paddles on
either side of the game window. To hit the moving ball, we have to move the paddles up and
down. A player’s score rises when we hits the ball or when the opponent miss the hit. To hit
the moving ball we basically use the ‘W’, ‘S’ or up, down keys on keyboard but the fun part
of my project is we can control this game using hand gestures. Basically camera track our
hand position an accordingly place the paddles at the position. As a player strikes the ball to
predefined speed level, the speed of the ball rises, as does the score. When player misses a
hit, the ball restarts from the centre towards the other player, with the opponent’s score
increasing.
There are thousands of game developed at all times and multiple ping pong game as
well but my project is little different because we can play it by using hand gesture as
explained above. Basically the idea of this game came from the car game which is controlled
by hand gestures.
Roll No. : 96 Page |7
TYBSc.CS Ping Pong Mania
1.1 Purpose
The goal of the Project Ping Pong Mania is to create a simple Ping pong game with
some minor change that is adding a hand gesture module. All of us are aware about the game
called Ping Pong which has two paddles and we control that paddles vertically using
keyboard or some type of controllers, what if we don’t have controller or keyboard ?, we
played multiple games with controller and keyboards, now let’s play it differently, our project
called Ping Pong Mania is allow us to play this game differently that is using hand gestures,
we can play this game using our left and right hand, in normal ping pong game we have to
move paddles upward or downwards to defend ourself, but in this case we need to move our hands
vertically to control the paddles.
1.2 Drawbacks
i) Cannot play multiplayer with others in online mode.
ii) Game is too simple.
iii) No levels
iv) Hand Detector module is not too accurate.
v) This game is addictive.
Roll No. : 96 Page |8
TYBSc.CS Ping Pong Mania
Chapter 2: Requirement
2.1 Modules
• NumPy: NumPy is a module for doing any kind of mathematical operations in
Python. It allows you to do is work with array like objects of multiple dimensions
like matrices and all kind of complicated three-dimension, four dimension, five
dimensional math very fast.
• HandTrackingModule: Hand tracking is the process in which a computer uses
computer vision to detect a hand from an input image and keeps focus on the
hand’s movement and orientation. Hand tracking allows us to develop numerous
programs that use hand movement and orientation as their input.
Roll No. : 96 Page |9
TYBSc.CS Ping Pong Mania
2.2 Front End & Back End-Python
Python is a high-level, general-purpose programming language. Its design philosophy
emphasizes code readability with the use of significant indentation. Python is dynamically typed
and garbage-collected. It supports multiple programming paradigms, including structured, object-
oriented and functional programming.
Roll No. : 96 P a g e | 10
TYBSc.CS Ping Pong Mania
2.4 Hardware
• Camera: any working web cam
• Operating system: Windows xp or Higher
• Hard Disk: Minimum 200MB space required
• RAM: 1GB or more
2.5 Software
• Front End and Back End: Python
• Development Environment: PyCharm Community Edition 2022.1.3
• Operation System: Windows 11
Roll No. : 96 P a g e | 11
TYBSc.CS Ping Pong Mania
Chapter 3: System Design
3.1 Gantt Chart
Roll No. : 96 P a g e | 12
TYBSc.CS Ping Pong Mania
3.2 UML Diagrams
i) Use Case Diagram
Roll No. : 96 P a g e | 13
TYBSc.CS Ping Pong Mania
ii) Flow Chart
Roll No. : 96 P a g e | 14
TYBSc.CS Ping Pong Mania
3.3 Coding
import cv2
import cvzone
from cvzone.HandTrackingModule import HandDetector
import numpy as np
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
# Importing all images
imgBackground = cv2.imread("Resources/Background.png")
imgGameOver = cv2.imread("Resources/gameOver.png")
imgBall = cv2.imread("Resources/Ball.png", cv2.IMREAD_UNCHANGED)
imgBat1 = cv2.imread("Resources/bat1.png", cv2.IMREAD_UNCHANGED)
imgBat2 = cv2.imread("Resources/bat2.png", cv2.IMREAD_UNCHANGED)
# Hand Detector
detector = HandDetector(detectionCon=0.8, maxHands=2)
# Variables
ballPos = [100, 100]
speedX = 20
speedY = 20
gameOver = False
score = [0, 0]
while True:
_, img = cap.read()
img = cv2.flip(img, 1)
imgRaw = img.copy()
# Find the hand and its landmarks
hands, img = detector.findHands(img, flipType=False) # with draw
# Overlaying the background image
img = cv2.addWeighted(img, 0.2, imgBackground, 0.8, 0)
# Check for hands
if hands:
for hand in hands:
x, y, w, h = hand['bbox']
h1, w1, _ = imgBat1.shape
y1 = y - h1 // 2
y1 = np.clip(y1, 20, 415)
if hand['type'] == "Left":
img = cvzone.overlayPNG(img, imgBat1, (59, y1))
if 59 < ballPos[0] < 59 + w1 and y1 < ballPos[1] < y1 + h1:
speedX = -speedX
Roll No. : 96 P a g e | 15
TYBSc.CS Ping Pong Mania
ballPos[0] += 30
score[0] += 1
if hand['type'] == "Right":
img = cvzone.overlayPNG(img, imgBat2, (1195, y1))
if 1195 - 50 < ballPos[0] < 1195 and y1 < ballPos[1] < y1 +
h1:
speedX = -speedX
ballPos[0] -= 30
score[1] += 1
# Game Over
if ballPos[0] < 40 or ballPos[0] > 1200:
gameOver = True
if gameOver:
img = imgGameOver
cv2.putText(img, str(score[1] + score[0]).zfill(2), (585, 360),
cv2.FONT_HERSHEY_COMPLEX,
2.5, (200, 0, 200), 5)
# If game not over move the ball
else:
# Move the Ball
if ballPos[1] >= 500 or ballPos[1] <= 10:
speedY = -speedY
ballPos[0] += speedX
ballPos[1] += speedY
# Draw the ball
img = cvzone.overlayPNG(img, imgBall, ballPos)
cv2.putText(img, str(score[0]), (300, 650),
cv2.FONT_HERSHEY_COMPLEX, 3, (255, 255, 255), 5)
cv2.putText(img, str(score[1]), (900, 650),
cv2.FONT_HERSHEY_COMPLEX, 3, (255, 255, 255), 5)
img[580:700, 20:233] = cv2.resize(imgRaw, (213, 120))
cv2.imshow("Image", img)
key = cv2.waitKey(1)
if key == ord('r'):
ballPos = [100, 100]
speedX = 15
speedY = 15
gameOver = False
score = [0, 0]
imgGameOver = cv2.imread("Resources/gameOver.png")
Roll No. : 96 P a g e | 16
TYBSc.CS Ping Pong Mania
3.4 Testing
i) Main screen
Roll No. : 96 P a g e | 17
TYBSc.CS Ping Pong Mania
ii) Game Over Screen
Roll No. : 96 P a g e | 18
TYBSc.CS Ping Pong Mania
3.5 Conclusion & References
Conclusion:
In conclusion, the Python-based Ping Pong Mania game provides an engaging and
entertaining experience for players. The combination of user-friendly controls, responsive
gameplay, and vibrant graphics makes it a captivating option for both casual and avid gamers.
The incorporation of features such as adjustable difficulty levels, scoring system, and
multiplayer functionality enhances the overall gaming experience.
The game not only serves as a source of enjoyment but also showcases the versatility and
capabilities of Python in game development. The simplicity and readability of Python code
make it accessible for developers of various skill levels, allowing them to create interactive
and dynamic games like Ping Pong Mania.
As technology continues to advance, Python remains a popular choice for game development
due to its extensive libraries, community support, and cross-platform compatibility. The
success of Ping Pong Mania serves as a testament to the potential of Python in the gaming
industry.
Roll No. : 96 P a g e | 19
TYBSc.CS Ping Pong Mania
References:
Pygame Documentation:
Website: https://www.pygame.org/docs/
The official documentation for Pygame provides detailed information on how to use the
Pygame library for game development in Python.
Python Official Documentation:
Website: https://docs.python.org/3/
The official Python documentation is a valuable resource for understanding the Python
programming language and its features.
Real Python:
Website: https://realpython.com/
Real Python offers a variety of tutorials and articles covering different aspects of Python
programming, including game development.
GitHub Repository (Sample Code):
Provide a link to the GitHub repository where the source code for the Ping Pong Mania game
is hosted. Include documentation and instructions for running the game.
Stack Overflow:
Website: https://stackoverflow.com/
Stack Overflow is a community-driven platform where developers can seek solutions to
common programming issues. It can be a valuable resource for troubleshooting and problem-
solving during game development.
Python Game Development - A Practical Introduction:
Roll No. : 96 P a g e | 20
TYBSc.CS Ping Pong Mania
Book by Will McGugan
ISBN-13: 978-1803234171
This book provides a practical guide to game development using Python and Pygame,
offering insights into various aspects of creating games with Python.
In conclusion to be very good Ping Pong game. There are two players that can play the game at a
time. Each player can handle one of the paddles using the hand gestures (player 1 : left hand, player 2
: Right hand).
Roll No. : 96 P a g e | 21