Python Project
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING
Submitted by
Shivam kumar Singh
(22SCSE1011866) 4th Sem II Year
SCHOOL OF COMPUTING SCIENCE AND ENGINEERING
GREATER NOIDA, UTTAR PRADESH
2024 – 2025
1
2
3
ABSTRACT
The project titled "Catch the Ball" is a simple 2D arcade-style game developed using
Python and the Pygame library. The primary objective of the game is to catch falling
balls using a basket controlled by the player. This project is designed as an
introductory exercise in game development and graphical programming, aimed at
helping learners understand core concepts such as event-driven programming, collision
detection, real-time rendering, and user interaction.
The game interface consists of a basket positioned at the bottom of the screen that can
be moved left or right using keyboard arrow keys. Balls fall from the top at random
horizontal positions, and the player earns points by catching them. The game ends
when the player misses a certain number of balls. The program also tracks the score
and provides basic feedback like a “Game Over” message upon losing.
Through the development of this project, students or beginners gain hands-on
experience with the Pygame module and learn about key game design principles,
including frame updating, object movement, and UI feedback. The simplicity of the
game makes it ideal for educational purposes while leaving room for future
enhancements like multiple levels, increasing difficulty, sound effects, and high score
tracking.
.
4
5
CHAPTER 1
INTRODUCTION
This project titled "Catch the Ball" is a simple 2D arcade-
style game developed
using the Python pygame library. The objective of the game
is for the player to
catch falling balls using a movable basket. It is designed to
demonstrate basic
game development principles, including user input handling,
collision detection
, event loops, and graphical interface creation.
6
CHAPTER-2
Game Variations
1. Classic Catch
• Description: A fundamental children's game where
participants throw a ball, beanbag, or similar object back
and forth. It requires at least two players and is often played
casually in backyards, parks, or during family gatherings.
• Mechanics: Players toss the ball to each other, aiming to
catch it without dropping. Variations like the "Game of 21"
add scoring (e.g., 3 points for a chest-level catch, 2 for
slightly off-target, 1 for far off) to make it competitive.
• Suitability: Ideal for all ages, especially young children
(ages 4+) learning coordination. It’s adaptable for social
settings, introducing kids to group play by substituting
players.
CHAPTER 3
LEARNINGOUTCOMES
2. Catchball (Sport)
• Description: A team sport derived from volleyball, played
7
indoors on a court divided by a net with two teams of six
players. Players catch and throw the ball instead of hitting it,
making it easier to learn.
• Rules:
o The ball is served over the net, and teams have up to
three touches to return it.
o Points are scored on every rally (rally point system). A
set is won at 25 points (15 for a third set), with a two-
point lead required.
o Only front-row players can spike or block; back-row
players focus on defense. Liberos specialize in
defensive roles.
• Popularity: Growing globally, featured in events like the
2017 Maccabiah Games. Similar sports include Newcomb
Ball and Throwball.
Chapter4.
Game Description
The game screen displays a basket controlled by the player,
positioned at the bottom of the screen. Balls fall from the top
at random horizontal positions. The player must move the
basket left or right using the arrow keys to catch these balls.
8
Rules:
• Each ball caught increases the score.
• If a ball is missed (i.e., it touches the bottom without
being caught), it’s counted as a miss.
• The game ends after a certain number of misses (e.g., 5
miss
•
Chapter 5.
Features
• Real-time movement using keyboard input.
• Randomized falling ball positions.
• Score and miss counters.
• Game Over screen after reaching max misses.
• Restart functionality.
9
6. Implementation Details
Game Components:
• Basket: A rectangle controlled by the player.
• Ball: A circle or ellipse that falls vertically.
• Score System: Displays the number of balls caught.
• Miss Counter: Ends the game after a defined number of
missed balls.
10
11
• CHAPTER-6
• CODE
import pygame
import random
# Initialization
[Link]()
WIDTH, HEIGHT = 600, 400
screen = [Link].set_mode((WIDTH, HEIGHT))
clock = [Link]()
# Colors and Fonts
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
font = [Link](None, 36)
# Game Objects
12
basket = [Link](270, 370, 60, 20)
ball = [Link]([Link](0, 580), 0, 20, 20)
score, misses = 0, 0
running = True
while running:
[Link](WHITE)
[Link](screen, BLACK, basket)
[Link](screen, RED, ball)
for event in [Link]():
if [Link] == [Link]:
running = False
keys = [Link].get_pressed()
if keys[pygame.K_LEFT] and [Link] > 0:
basket.x -= 6
if keys[pygame.K_RIGHT] and [Link] < WIDTH:
basket.x += 6
13
ball.y += 5
if [Link](ball):
score += 1
ball.y = 0
ball.x = [Link](0, 580)
elif ball.y > HEIGHT:
misses += 1
ball.y = 0
ball.x = [Link](0, 580)
# Display Score and Misses
[Link]([Link](f"Score: {score}", True, BLACK), (10,
10))
[Link]([Link](f"Misses: {misses}", True, BLACK),
(10, 40))
# Game Over
if misses >= 5:
game_over = [Link]("Game Over!", True, RED)
[Link](game_over, (220, 180))
[Link]()
14
9. Conclusion
The "Catch the Ball" project is a great introduction to 2D game
development using Python and Pygame. It reinforces core
concepts in programming such as loops, conditionals, object
movement, and collision detection in a visual and interactive
way.
•
15
16