rendered paste body!/usr/bin/env pythonimport pygame, randomfrom pygame.locals import *pygame.init( )class Objects( pygame.sprite.Sprite ): def __init__( self, color, position ): pygame.sprite.Sprite.__init__( self ) self.image = pygame.Surface( [ 15, 5 ] ).convert( ) self.image.fill( color ) self.rect = self.image.get_rect( ) self.rect.topleft = position class DrawBall( pygame.sprite.Sprite ): def __init__ ( self, color, 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 )) self.rect.center = ( 50, 50 ) pygame.draw.circle( self.image, color, ( radius, radius ), radius ) def UpdateBall( self, velocity_x, velocity_y, _src_ ): if self.rect.bottom >= _src_.bottom: velocity_y -= velocity_y if self.rect.right >= _src_.right or self.rect.left <= 0: velocity_x = - velocity_x # if self.rect.right >= 200 -1 or self.rect.left <= 0: velocity_x = - velocity_x self.rect.move_ip( velocity_x, velocity_y ) _screen_ = pygame.display.set_mode( [ 200, 200 ] )_scrRect = _screen_.get_rect( )velocityX, velocityY = random.randint( 1, 5 ), random.randint( 1, 5 )objgroup =pygame.sprite.Group( )_ball = DrawBall( [ 255, 0, 0 ], 5 )for colors, pos in [ ( [ 255, 0, 0 ], [ 0, 5 ] ), ( [ 0, 255, 0 ], [ 15, 5 ] ), ( [ 0, 0, 255 ], [ 30, 5 ] ) ]: objgroup.add( Objects( colors, pos ))_loop_ = Truewhile pygame.event.poll( ).type != pygame.KEYDOWN: pygame.time.delay( 30 ) _screen_.fill(( 0, 0, 0 )) for b in objgroup.sprites( ): _screen_.blit( b.image, b.rect ) _ball.UpdateBall( velocityX, velocityY, _scrRect ) _screen_.blit( _ball.image, _ball.rect ) pygame.display.update( )