All pastes #75976 Raw Edit

xlordt

public python v1 · immutable
#75976 ·published 2006-06-30 20:36 UTC
rendered paste body
import 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.image.fill( color )				self.rect  = self.image.get_rect( )		self.rect.bottom = position				pygame.draw.rect( self.image, ( 0, 0, 255 ), self.rect )		screen = pygame.display.set_mode(( 150, 150 ))screen.fill(( 255, 255, 10 ))scrRect = screen.get_rect( )ball = MyBall( 5 )bar  = MakeBar(( 0, 0, 255 ), screen.get_height( ) - 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(( 255, 255, 10 ))		screen.blit( ball.image, ball.rect )	screen.blit( bar.image, bar.rect )		pygame.display.update( )	pygame.quit( )