Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame,sys
- import random
- from os import path
- WIDTH = 1300
- HEIGHT = 1200
- FPS = 30
- WHITE = (255, 255, 255)
- BLACK = (0, 0, 0)
- RED = (255, 0, 0)
- GREEN = (0, 255, 0)
- BLUE = (0, 0, 255)
- BROWN = (195, 171, 133)
- PINK = (255, 138, 154)
- ORANGE = (255, 95, 0)
- PURPLE = (255, 0, 255)
- pygame.init()
- pygame.mixer.init()
- screen = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption("BaseballDefense3000")
- clock = pygame.time.Clock()
- background_image = pygame.image.load("BBallfield.png").convert()
- OUTS = 0
- lead_x = 626
- lead_y = 420
- firstBaseX = 870
- firstBaseY = 420
- pitchlandx = random.randint(250,1000)
- pitchlandy = random.randint(10, 750)
- #test pitches
- #pitchlandx = random.randint(870,870)
- #pitchlandy = random.randint(420,420)
- class Batter():
- def __init__(self):
- pygame.draw.rect(background_image, BLUE, [625, 690, 20, 20])
- class Fielder():
- def __init__(self):
- global pitchlandx
- global pitchlandy
- global firstBaseX
- #pitcher
- pygame.draw.rect(background_image, RED, [625,420, 20, 20])
- if pitchlandx in range(525, 725) and pitchlandy in range(320, 520):
- pygame.draw.rect(background_image, BLACK, [625, 420, 25, 25])
- #base 1
- pygame.draw.rect(background_image, RED, [870, 420, 20, 20])
- if pitchlandx in range(820, 920) and pitchlandy in range(370,470):
- pygame.draw.rect(background_image, BLACK, [870, 420, 25, 25])
- OUTS += 1
- #base 2
- pygame.draw.rect(background_image, RED, [625, 185, 20, 20])
- if pitchlandx in range(575, 675) and pitchlandy in range(135, 235):
- pygame.draw.rect(background_image, BLACK, [625, 185, 25, 25])
- OUTS += 1
- #base 3
- pygame.draw.rect(background_image, RED, [380, 420, 20, 20])
- if pitchlandx in range(330, 430) and pitchlandy in range(370, 470):
- pygame.draw.rect(background_image, BLACK, [380, 420, 25, 25])
- OUTS += 1
- #ss
- pygame.draw.rect(background_image, RED, [500, 300, 20, 20])
- if pitchlandx in range(400,600) and pitchlandy in range(200,400):
- pygame.draw.rect(background_image, BLACK, [500, 300, 25, 25])
- OUTS += 1
- #rfielder
- pygame.draw.rect(background_image, RED, [870, 220, 20, 20])
- if pitchlandx in range (855, 895) and pitchlandy in range(195, 245):
- pygame.draw.rect(background_image, BLACK, [870, 220, 25, 25])
- OUTS += 1
- #cfielder
- pygame.draw.rect(background_image, RED, [625, 85, 20, 20])
- if pitchlandx in range (600, 650) and pitchlandy in range (60, 110):
- pygame.draw.rect(background_image, BLACK, [625, 85, 25, 25])
- OUTS += 1
- #lfielder
- pygame.draw.rect(background_image, RED, [380, 200, 20, 20])
- if pitchlandx in range(355, 405) and pitchlandy in range(175, 225):
- pygame.draw.rect(background_image, BLACK [380, 200, 25, 25])
- OUTS += 1
- #catcher
- pygame.draw.rect(background_image, RED, [625, 720, 20, 20])
- if pitchlandx in range (600, 650) and pitchlandy in range(695, 725):
- pygame.draw.rect(background_image, BLACK, [625, 720, 20, 20])
- OUTS += 1
- if OUTS == 3:
- print('Retire the side!')
- class Pitch():
- def __init__(self):
- global lead_y
- global lead_x
- global pitchlandx
- global pitchlandy
- pygame.draw.circle(background_image, PURPLE, (lead_x, lead_y), 6, 0)
- if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
- if event.key == pygame.K_DOWN:
- lead_y += 15
- if lead_y == 660:
- pygame.draw.circle(background_image, ORANGE, (pitchlandx,pitchlandy),6 ,0)
- # Game loop
- running = True
- while running:
- # keep loop running at the right speed
- clock.tick(FPS)
- # Process input (events)
- for event in pygame.event.get():
- print(event)
- if event.type == pygame.QUIT:
- running = False
- screen.fill(BROWN)
- screen.blit(background_image, [0, 0])
- Batter()
- Fielder()
- Pitch()
- pygame.display.update()
- screen.fill(BROWN)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement