rendered paste body#!/usr/bin/env pythonimport pygame, random, sysfrom pygame.locals import *pygame.init( )class MyBall( pygame.sprite.Sprite ): def __init__ ( self, radius ): pygame.sprite.Sprite.__init__( self ) self.image = pygame.Surface(( 2 * radius, 2 * radius )).convert( ) self.rect = self.image.get_rect( ) self.image.set_colorkey(( 0, 0, 0 )) pygame.draw.circle( self.image, ( 1, 5, 255 ), ( radius, radius ), radius ) self.rect.move_ip( 10, 10 ) def update( self, x, y ): self.rect.move_ip( x, y ) class MakeBar( pygame.sprite.Sprite ): def __init__( self, color, position ): pygame.sprite.Sprite.__init__( self ) self.image = pygame.Surface(( 25, 5 )).convert( ) self.rect = self.image.get_rect( ) pygame.draw.rect( self.image, color, self.rect ) self.rect.bottom = position def Update( move_l, move_r ): self.rect.move_ip( move_l, move_r ) screen = pygame.display.set_mode(( 150, 150 ))screen.fill(( 5, 5, 10 ))scrRect = screen.get_rect( )ball = MyBall( 5 )bar = MakeBar(( 0, 0, 255 ), scrRect.bottom - 10 )g = pygame.sprite.OrderedUpdates( )velocity_x = random.randint( 1, 5 )velocity_y = random.randint( 1, 5 )pygame.key.set_repeat( 1, 1 );looping = Truewhile looping: pygame.time.delay( 50 ) for events in pygame.event.get( ): if events.type == pygame.QUIT: looping = False if ball.rect.right >= scrRect.right or ball.rect.left == 0: velocity_x = - velocity_x if ball.rect.top == scrRect.top: velocity_y = - velocity_y ball.update( velocity_x, velocity_y ) screen.fill(( 5, 5, 10 )) screen.blit( ball.image, ball.rect ) screen.blit( bar.image, bar.rect ) pygame.display.update( ) pygame.quit( )