#Simulation of bouncing ball game using pygame
# Define colors
purple (128, 0, 128)
white = (255, 255, 255)
# Define ball settings
ball_radius 40
ball_ x, ball_y = 100, 100
ball_obj = pygame, Surface((baliradius * 2, ball_radius * 2), pygane. SRCALPHA)
[Link](
#Ballspeed (x
balobj, purple, (ball_radlus, ball_radius), [Link])
and y directions)
speed = [1, 1]
# Game loop
running = Thue
while running:
# Event loop
for event in [Link]):
if [Link] == pygame, QUTT:
oF EN
running= False
#Qear the screen with white color
[Link]( white)
# Move the ball
ballxt= speed[OT
bali_y += speed[1|
# Check for collision with walls
if ball_x -bali_radius < 0 or ball_x + ball_radius >= width:
speed [o]= -speed[O] # Reverse Xdirection
if bal_y - ball_radiuS <= 0 orbali_y+ ball radius >= height:
speed[1]= speed[1] # Reverse Ydirection
# Draw the ball at its new position
[Link](ball_obj,(ball_x- bal_radius, bal_y - ball_radius)
# Update the display
[Link]. flip()
# Quit pygarme
[Link]()
Car qame USin pygame
import pyaame
# Initialize Pyaame
pyaame. init()
# Set up the display
display width 800
display height. = 600
aameDisplay = [Link]. set mode( (display width, display_height) )
[Link]. set caption("A bit Racey")
# Colors
black
white (255, 255, 255)
# Set up the clock
clock pygame. time. Clock()
# Load Gar image (replace wit.h your actual imaae file)
Carlmg = pygame. image. load( car. png') # Make sure you have a car image 1n
the directory
# Function to draw the car G O L
def car(x, y):
[Link](carlma, (x, y) )
OF ENG
# Initial car position
display width * 0.45
y = display heiaht * 0. 8
# Game loop flag
Grashed = False
# Main game loop
while not CGrashed:
for aVent in [Link]. qet( ):
if eent..type [Link]:
Crashed # True
# Fill the screen with whit.e coior
[Link](white)
# Draw the Car at the current position
Garx, y)
# Update the display
[Link] , update()
# Set. the frame rat.e
[Link]í60)
# Quit. the aame TiRUCH RAPE
PALLI
[Link] t( )
quit( )