Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.40 KB | None | 0 0
  1. import pygame,sys
  2. import random
  3.  
  4.  
  5. from os import path
  6.  
  7. WIDTH = 1300
  8. HEIGHT = 1200
  9. FPS = 30
  10.  
  11. WHITE = (255, 255, 255)
  12. BLACK = (0, 0, 0)
  13. RED = (255, 0, 0)
  14. GREEN = (0, 255, 0)
  15. BLUE = (0, 0, 255)
  16. BROWN = (195, 171, 133)
  17. PINK = (255, 138, 154)
  18. ORANGE = (255, 95, 0)
  19. PURPLE = (255, 0, 255)
  20.  
  21.  
  22. pygame.init()
  23. pygame.mixer.init()
  24. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  25. pygame.display.set_caption("BaseballDefense3000")
  26. clock = pygame.time.Clock()
  27.  
  28. background_image = pygame.image.load("BBallfield.png").convert()
  29.  
  30. OUTS = 0
  31.  
  32. lead_x = 626
  33. lead_y = 420
  34.  
  35. firstBaseX = 870
  36. firstBaseY = 420
  37. pitchlandx = random.randint(250,1000)
  38. pitchlandy = random.randint(10, 750)
  39.  
  40. #test pitches
  41. #pitchlandx = random.randint(870,870)
  42. #pitchlandy = random.randint(420,420)
  43.  
  44.        
  45. class Batter():
  46.     def __init__(self):
  47.         pygame.draw.rect(background_image, BLUE, [625, 690, 20, 20])
  48.        
  49.        
  50. class Fielder():
  51.     def __init__(self):
  52.         global pitchlandx
  53.         global pitchlandy
  54.         global firstBaseX
  55.  
  56.        
  57.         #pitcher
  58.         pygame.draw.rect(background_image, RED, [625,420, 20, 20])
  59.         if pitchlandx in range(525, 725) and pitchlandy in range(320, 520):
  60.             pygame.draw.rect(background_image, BLACK, [625, 420, 25, 25])
  61.         #base 1
  62.         pygame.draw.rect(background_image, RED, [870, 420, 20, 20])
  63.         if pitchlandx in range(820, 920) and pitchlandy in range(370,470):
  64.             pygame.draw.rect(background_image, BLACK, [870, 420, 25, 25])
  65.             OUTS += 1
  66.         #base 2
  67.         pygame.draw.rect(background_image, RED, [625, 185, 20, 20])
  68.         if pitchlandx in range(575, 675) and pitchlandy in range(135, 235):
  69.             pygame.draw.rect(background_image, BLACK, [625, 185, 25, 25])
  70.             OUTS += 1
  71.         #base 3
  72.         pygame.draw.rect(background_image, RED, [380, 420, 20, 20])
  73.         if pitchlandx in range(330, 430) and pitchlandy in range(370, 470):
  74.             pygame.draw.rect(background_image, BLACK, [380, 420, 25, 25])
  75.             OUTS += 1
  76.         #ss
  77.         pygame.draw.rect(background_image, RED, [500, 300, 20, 20])
  78.         if pitchlandx in range(400,600) and pitchlandy in range(200,400):
  79.             pygame.draw.rect(background_image, BLACK, [500, 300, 25, 25])
  80.             OUTS += 1
  81.         #rfielder
  82.         pygame.draw.rect(background_image, RED, [870, 220, 20, 20])
  83.         if pitchlandx in range (855, 895) and pitchlandy in range(195, 245):
  84.             pygame.draw.rect(background_image, BLACK, [870, 220, 25, 25])
  85.             OUTS += 1
  86.         #cfielder
  87.         pygame.draw.rect(background_image, RED, [625, 85, 20, 20])
  88.         if pitchlandx in range (600, 650) and pitchlandy in range (60, 110):
  89.             pygame.draw.rect(background_image, BLACK, [625, 85, 25, 25])
  90.             OUTS += 1
  91.         #lfielder
  92.         pygame.draw.rect(background_image, RED, [380, 200, 20, 20])
  93.         if pitchlandx in range(355, 405) and pitchlandy in range(175, 225):
  94.             pygame.draw.rect(background_image, BLACK [380, 200, 25, 25])
  95.             OUTS += 1
  96.         #catcher
  97.         pygame.draw.rect(background_image, RED, [625, 720, 20, 20])
  98.         if pitchlandx in range (600, 650) and pitchlandy in range(695, 725):
  99.             pygame.draw.rect(background_image, BLACK, [625, 720, 20, 20])
  100.             OUTS += 1
  101.            
  102.         if OUTS == 3:
  103.             print('Retire the side!')
  104.  
  105.  
  106.  
  107. class Pitch():
  108.     def __init__(self):
  109.         global lead_y
  110.         global lead_x
  111.         global pitchlandx
  112.         global pitchlandy
  113.        
  114.         pygame.draw.circle(background_image, PURPLE, (lead_x, lead_y), 6, 0)
  115.        
  116.         if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
  117.             if event.key == pygame.K_DOWN:
  118.                 lead_y += 15
  119.             if lead_y == 660:
  120.                 pygame.draw.circle(background_image, ORANGE, (pitchlandx,pitchlandy),6 ,0)
  121.                
  122. # Game loop
  123. running = True
  124. while running:
  125.     # keep loop running at the right speed
  126.     clock.tick(FPS)
  127.     # Process input (events)
  128.     for event in pygame.event.get():
  129.         print(event)
  130.      
  131.         if event.type == pygame.QUIT:
  132.             running = False
  133.    
  134.     screen.fill(BROWN)
  135.     screen.blit(background_image, [0, 0])
  136.    
  137.    
  138.     Batter()
  139.     Fielder()
  140.     Pitch()
  141.        
  142.    
  143.  
  144.     pygame.display.update()
  145.     screen.fill(BROWN)
  146.    
  147. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement