CCS347 GAME DEVELOPMENT
A MINI PROJECT REPORT
Submitted by
DHANUSH B
420422104016
in partial fulfillment for the award of the degree of
BACHELOR OF ENGINEERING
In
COMPUTER SCIENCE AND ENGINEERING
ADHIPARASAKTHI ENGINEERING COLLEGE
MELMARUVATHUR-603 31G
ANNA UNIVERSITY: CHENNAI 600 025
MAY 2025
“Ball Bouncing and Catch the Ball”
Description:
Ball bouncing and catching mechanics are fundamental components in many 2D and 3D
casual and arcade games. These mechanics simulate realistic or arcade-style physics to create
engaging and interactive gameplay. Implementing these features effectively enhances the
player experience by adding challenge, responsiveness, and a sense of reward.
Key Features:
• Realistic or Arcade-Style Physics: Simulates gravity, motion, and energy loss during
bounces to create dynamic ball movement.
• Collision Detection: Identifies when the ball interacts with game elements like walls, floor,
or the catcher.
• Bounce Factor Control: Allows tuning how high or far the ball bounces after hitting a
surface.
• Player-Controlled Catch Mechanism: The user controls a paddle, basket, or character to
catch falling balls.
• Scoring System: Points are awarded for successful catches, motivating the player.
• Game Feedback: Visual (animations, effects) and audio cues provide satisfying feedback
on bounces and catches.
Tools Technologies Used:
• Python
• Pygame
• Audio/Visual Assets (images and sound effects)
Implementation :
1. Set Up the Environment
• Install pygame:
“pip install pygame”
2. Initialize Game Settings
• Import required modules: pygame, random, math, mixer.
• Initialize Pygame using pygame.init().
• Create a game window of size 1200x800 with a title and icon.
• Load and scale the background image.
3. Ball Movement and Bouncing Logic
Code :
ball.velocity.y += gravity * deltaTime
ball.position += ball.velocity * deltaTime
Bounce Logic:
• Vertical velocity is inverted when hitting horizontal surfaces.
• Horizontal velocity is inverted when hitting vertical surfaces.
• Velocity is scaled by a bounce factor to simulate energy loss.
4. Define Game Elements
• Ball:
Description: The central object that moves, bounces off surfaces, and must be caught
Attributes:
• Position (X, Y)
• Velocity (X, Y)
• Radius (size)
• Catcher (Player-Controlled Object):
• Position (X, Y)
• Grants temporary invincibility.
• Only one bullet on screen at a time.
• Environment:
• 3-lane track with scrolling background.
• Road markings for visual guidance.
• Collision Detection:
If bullet hits enemy: play explosion, show effect, respawn enemy, increase
score.
5. Main Game Loop
• Spawn new obstacles at intervals.
• Move existing ones downward (increasing speed with score).
• Delete off-screen obstacles.Update bullet position.
• Update positions/sizes of exhaust/explosion effects.
• Remove expired particles.
• Update positions/sizes of exhaust/explosion effects.
• Remove expired particles.
6. End Game Conditions
7. Fairness: Clear rules for failure (avoidable obstacles).
8. Replayability: Quick restart option keeps players engaged.
9. Feedback: Immediate visual/audio cues for player awareness
Code :
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Game Window
WIDTH, HEIGHT = 600, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Ball Bouncing & Catch Game")
# Colors
WHITE = (255, 255, 255)
RED = (255, 50, 50)
BLUE = (50, 100, 255)
BLACK = (0, 0, 0)
# Clock
clock = pygame.time.Clock()
FPS = 60
# Ball properties
ball_radius = 15
ball_x = random.randint(ball_radius, WIDTH - ball_radius)
ball_y = ball_radius
ball_speed_x = 3
ball_speed_y = 3
gravity = 0.2
bounce_factor = -0.8
# Paddle (catcher) properties
paddle_width = 100
paddle_height = 15
paddle_x = WIDTH // 2 - paddle_width // 2
paddle_y = HEIGHT - 40
paddle_speed = 7
# Game variables
score = 0
lives = 3
font = pygame.font.SysFont(None, 32)
def draw_ball(x, y):
pygame.draw.circle(screen, RED, (int(x), int(y)), ball_radius)
def draw_paddle(x):
pygame.draw.rect(screen, BLUE, (x, paddle_y, paddle_width, paddle_height))
def draw_text(text, x, y, color=WHITE):
label = font.render(text, True, color)
screen.blit(label, (x, y))
# Game Loop
running = True
while running:
screen.fill(BLACK)
# Event Handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Paddle Movement
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and paddle_x > 0:
paddle_x -= paddle_speed
if keys[pygame.K_RIGHT] and paddle_x < WIDTH - paddle_width:
paddle_x += paddle_speed
# Ball Physics
ball_x += ball_speed_x
ball_y += ball_speed_y
ball_speed_y += gravity
# Wall Collision
if ball_x <= ball_radius or ball_x >= WIDTH - ball_radius:
ball_speed_x *= -1
if ball_y <= ball_radius:
ball_y = ball_radius
ball_speed_y *= bounce_factor
# Paddle Collision (Catch)
if (paddle_y <= ball_y + ball_radius <= paddle_y + paddle_height and
paddle_x <= ball_x <= paddle_x + paddle_width):
ball_y = paddle_y - ball_radius
ball_speed_y *= bounce_factor
score += 1
# Missed Ball
if ball_y > HEIGHT:
lives -= 1
ball_x = random.randint(ball_radius, WIDTH - ball_radius)
ball_y = ball_radius
ball_speed_y = 3
if lives <= 0:
running = False
# Draw Game Elements
draw_ball(ball_x, ball_y)
draw_paddle(paddle_x)
draw_text(f"Score: {score}", 10, 10)
draw_text(f"Lives: {lives}", 10, 40)
pygame.display.update()
clock.tick(FPS)
# Game Over
screen.fill(BLACK)
draw_text("Game Over", WIDTH // 2 - 80, HEIGHT // 2 - 20)
draw_text(f"Final Score: {score}", WIDTH // 2 - 90, HEIGHT // 2 + 20)
pygame.display.update()
pygame.time.wait(3000)
pygame.quit()
sys.exit()
Code Link :
Complete file :
"Ball Bouncing and catch the ball " game
Output :
Conclusion:
The Ball Bouncing and Catch the Ball game successfully demonstrates fundamental
concepts of 2D game development, including physics simulation, collision detection, player
interaction, and state management. By implementing the game in Pygame, we were able to
create a functional and interactive application that incorporates real-time ball movement,
gravity, bouncing behavior, and responsive player controls.