# Bouncing ball
# Program
# Bouncing ball
import sys, pygame
pygame.init()
size = width, height = 700, 250
speed = [1, 1]
background = 255, 255, 255
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Bouncing ball")
ball = pygame.image.load("ball.jpg")
ballrect = ball.get_rect()
while 1:
pygame.time.delay(2)
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(background)
screen.blit(ball, ballrect)
pygame.display.flip()
ball.jpg
Output:
message me if u need any help
ReplyDeleteProvide the algorithm link
ReplyDeletehttps://drranurekha.blogspot.com/2019/11/bouncing-ball-pygame.html
DeleteMam I want algorithm for this bouncing ball program
ReplyDeleteI got it also very easy to understood
ReplyDeletei cann't solve the error in 2nd line that "init" error
ReplyDeleteplease tell me how to solve it?
install compatible version of pygame and python and make sure path are set correctly
DeleteHello and thank you for the algorithm but what if i want to put for example 8 bouncing balls? Thank you very much :)
ReplyDelete