import pygame, os, sys, random from Numeric import * from pygame.locals import * #Initualize Pygame pygame.init( ) fonts = pygame.font.Font( None, 26 ) #Set sizes, and colors for the game _colors_ = { "black" : (0, 0, 0), "red" : (255, 0, 0), "blue" : ( 0, 0, 255 ), "white" : ( 255, 255, 255 )} screensize = ( 300, 300 ) stick_height, stick_width = 5, 20 #Create the game window windows = pygame.display.set_mode( screensize ) #Create the Stick stick_line = pygame.Surface(( stick_width, stick_height )) stick_pos = ( 100, windows.get_height( ) - stick_line.get_height( ) -10 ) stick_rect = stick_line.get_rect( center=stick_pos ) #Create the ball sball = pygame.Surface(( 10, 10 )) ball = pygame.draw.circle( sball, _colors_['blue'], ( 4, 6 ), 5, 0 ) rball = sball.get_rect( ) stick_line.fill(( 255, 0, 0 )) position_x, position_y = 0, 0 velocity_x, velocity_y = random.randint( 10, 15 ), random.randint( 10, 15 ) pygame.key.set_repeat( 1 ); while True: rball.move_ip( velocity_x, velocity_y ) pygame.time.delay( 100 ) if( rball.right >= screensize[0] ) or ( rball.left <= 0 ): velocity_x = -velocity_x if( rball.top <= windows.get_rect( ).top ): velocity_y = - velocity_y if( stick_rect.colliderect( rball )): velocity_y = - velocity_y #Just incase you decicde to hit that [x] for events in pygame.event.get( ): if ( events.type == pygame.QUIT ): pygame.quit( ); sys.exit( ) #Lets get key events now if events.type == pygame.KEYDOWN: if ( events.key == K_LEFT ): stick_rect.move_ip( -10, 0 ); if ( events.key == K_RIGHT ): stick_rect.move_ip( 10, 0 ); #Lets make sure that we dont go off the Screen window if stick_rect.left < 0: stick_rect.left = 0 if stick_rect.right >= screensize[0]: stick_rect.right = screensize[0] #Ok, Lets put it all together now shall we ;) windows.fill(( 0, 0, 0 )) windows.blit( stick_line, stick_rect ) windows.blit( sball, rball ) pygame.display.flip( )