Advertisement
Mr-A

The A-Ping Pong V0.01

Sep 6th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. import pygame,sys
  2. from pygame.locals import*
  3. pygame.init()
  4. SF=pygame.display.set_mode((600,600), pygame.DOUBLEBUF)
  5. pygame.display.set_caption('A-Ping Pong (Idea by Hackermakduf)')
  6. SF.fill((0, 0, 0))
  7. FPS=60
  8. pygame.mouse.set_visible(False)
  9. ball={"rect":[SF.get_rect().centerx, SF.get_rect().centery, 20, 20],
  10.       "dir_vector" : [-5, 3],
  11.       "radius" : 10,
  12.       "color": (0, 255, 0)}
  13. plate_1={"rect": [250, SF.get_height()-25, 100, 50],
  14.         "color": (255, 0, 0), "speed":10}
  15. plate_2={"rect": [250, -25, 100, 50],
  16.         "color": (0, 0, 255), "speed":10}
  17.          
  18. FPS_CLOCK=pygame.time.Clock()
  19. RIGHT1, RIGHT2, LEFT1, LEFT2 = False, False, False, False
  20. while True:
  21.     for event in pygame.event.get():
  22.         if event.type==QUIT:
  23.             pygame.quit()
  24.             sys.exit()
  25.         if event.type==KEYDOWN:
  26.             if event.key==K_RIGHT:
  27.                 RIGHT1= True
  28.             if event.key==K_d:
  29.                 RIGHT2= True            
  30.             if event.key==K_LEFT:
  31.                 LEFT1=True
  32.             if event.key==K_a:
  33.                 LEFT2=True
  34.         if event.type==KEYUP:
  35.             if event.key==K_RIGHT:
  36.                 RIGHT1= False
  37.             if event.key==K_d:
  38.                 RIGHT2= False            
  39.             if event.key==K_LEFT:
  40.                 LEFT1=False
  41.             if event.key==K_a:
  42.                 LEFT2=False      
  43.                
  44.     SF.fill((0, 0, 0))
  45.  
  46.     #Check_For_Collision:
  47.     if ball["rect"][0]-ball["radius"] <= 10 or ball["rect"][0]+ball["radius"] >= SF.get_width()-10:
  48.         ball["dir_vector"][0]*=-1
  49.     if ball["rect"][1] <= 5 or ball["rect"][1]+ball["radius"] >= SF.get_height()-10:
  50.         ball["dir_vector"][1]*=-1
  51.     #Check_For_Collision_end:
  52.     #Add_Velocities:
  53.     ball["rect"][0]+=ball["dir_vector"][0]
  54.     if ball["rect"][0]-ball["radius"] < 10:
  55.         ball["rect"][0]=10+ball["radius"]
  56.     elif ball["rect"][0]+ball["radius"] > SF.get_width()-10:
  57.         ball["rect"][0]=SF.get_width()-10-ball["radius"]
  58.  
  59.        
  60.     ball["rect"][1]+=ball["dir_vector"][1]
  61.     #Add_Velocities_end:
  62.     #Draw_Borders:
  63.     pygame.draw.line(SF, (255, 255, 255),(5, SF.get_height()), (5, 0), 10)
  64.     pygame.draw.line(SF, (255, 255, 255),(SF.get_width()-5, SF.get_height()), (SF.get_width()-5, 0), 10)
  65.     #Draw_Borders_end:
  66.     #Draw_Ball:
  67.     pygame.draw.circle(SF, ball["color"], (ball["rect"][0], ball["rect"][1]),
  68.                        ball["radius"], 4)
  69.  
  70.     #Draw_Ball_end:
  71.     #Draw_Plate_1:
  72.     pygame.draw.arc(SF, plate_1["color"], plate_1["rect"], 20, 160, 10)
  73.  
  74.     #Draw_Plate_2:
  75.     pygame.draw.arc(SF, plate_2["color"], plate_2["rect"], 20, 160, 10)
  76.     if RIGHT1:
  77.         plate_1["rect"][0]+=plate_1["speed"]
  78.     if LEFT1:
  79.         plate_1["rect"][0]-=plate_1["speed"]
  80.     if RIGHT2:
  81.         plate_2["rect"][0]+=plate_2["speed"]
  82.     if LEFT2:
  83.         plate_2["rect"][0]-=plate_2["speed"]
  84.     pygame.display.flip()
  85.     FPS_CLOCK.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement