I get the parts of where they are commented, but what I don't get it the ones that are in , ad well as things like (size /2])... etcetera.
Here is the code:
Code: Select all
# BAT AND BALL # By antiloquax - 28th April 2012 import pygame from pygame.locals import * pygame.init() # set the width and height of the screen size = [400, 400] screen = pygame.display.set_mode(size) # give the window a title pygame.display.set_caption("Bat and Ball") # This makes the normal mouse pointer invisible in graphics window pygame.mouse.set_visible(0) # create surfaces for the bat and ball bat_surf = pygame.Surface((64,12)) bat_surf.fill((0,255,0)) batrect = bat_surf.get_rect() ball_surf = pygame.Surface((30,30)) ballrect = ball_surf.get_rect() ball = pygame.draw.circle(ball_surf, (0,0,255),[15, 15], 15) # set speed of ball speed = [3, 3] # puts the bat center of screen, near the bottom batrect.center = ((size/2), (size - 50)) # make a text object font = pygame.font.Font(None, 36) text = font.render("Game Over", True, (255,0,0)) textRect = text.get_rect() textRect.centerx = (size/2) textRect.centery = (size/2) # loop until the user clicks the close button done=0 # create a timer to control how often the screen updates clock = pygame.time.Clock() # main game loop while done == 0: screen.fill((0,0,0)) # event handling for event in pygame.event.get(): # if we click something ... if event.type == pygame.QUIT: # if we click close ... done=1 # this will cause the loop to finish. # moves bat in accordance with the mouse position position = pygame.mouse.get_pos() batrect.centerx = position # move the ball ballrect.left += speed ballrect.top += speed # collision detection if ballrect.colliderect(batrect): speed = -speed # check if the ball is going off screen if ballrect.left < 0 or ballrect.right > size: speed = -speed if ballrect.top < 0: speed = -speed # print "Game Over" if the ball leaves screen if ballrect.top > size: screen.blit(text, textRect) pygame.display.flip() pygame.time.wait(2000) # 2000 milliseconds pause ballrect.top=0; ballrect.left=(size/2) # reset the ball position screen.blit(ball_surf, ballrect) screen.blit(bat_surf, batrect) # set the loop to 60 cycles per second clock.tick(60) # update the display pygame.display.flip()