Ccs347 Game Development: Dhanush B 420422104016
Ccs347 Game Development: Dhanush B 420422104016
Submitted by
DHANUSH B
420422104016
BACHELOR OF ENGINEERING
In
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.
• 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.
Implementation :
1. Set Up the Environment
• Install pygame:
Bounce Logic:
Description: The central object that moves, bounces off surfaces, and must be caught
Attributes:
• Position (X, Y)
• Velocity (X, Y)
• Radius (size)
• Position (X, Y)
If bullet hits enemy: play explosion, show effect, respawn enemy, increase
score.
5. Main Game Loop
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
# Game variables
score = 0
lives = 3
font = pygame.font.SysFont(None, 32)
def draw_paddle(x):
pygame.draw.rect(screen, BLUE, (x, paddle_y, paddle_width, paddle_height))
# 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
# 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
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 :