From 6256ed227017cb04220bfcd4212bfab8bf9ac0d6 Mon Sep 17 00:00:00 2001 From: bertieb Date: Mon, 30 Nov 2020 15:58:50 +0000 Subject: [PATCH] Animates team selection --- teampicker.py | 56 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/teampicker.py b/teampicker.py index 55743bf..7e3a5bb 100644 --- a/teampicker.py +++ b/teampicker.py @@ -23,6 +23,10 @@ import pygame pygame.init() random.seed("BERTIE BEEF BAGGIO") +HIGHLIGHTEVENT = pygame.USEREVENT + 1 # user specified event +CLEAREVENT = pygame.USEREVENT + 2 # user specified event +CHOOSEEVENT = pygame.USEREVENT + 3 # user specified event + SIZE = WIDTH, HEIGHT = 1920, 1080 BGIMG = pygame.image.load("sub_crown_bg_2.png") @@ -33,6 +37,7 @@ SUBFONT = pygame.font.SysFont("Fetamont", SUBFONTHEIGHT) OFFWHITE = (224, 224, 224) HIGHLIGHT = (255, 209, 0) BLUE = (20, 25, 153) +RED = (186, 20, 31) PURPLE = (121, 35, 158) screen = pygame.display.set_mode(SIZE) @@ -91,6 +96,9 @@ class Team(object): def unhighlight(self): self.colour = OFFWHITE + def choose(self): + self.colour = RED + def draw(self): draw_text(self.team, FONT, self.colour, self.y, self.x) @@ -111,6 +119,31 @@ class Sub(object): self.x, int(self.y+SUBFONTHEIGHT)) +class Highlighter(object): + """For highlighting teams randomly""" + + def __init__(self): + self.team = None + self.iterations = 0 + self.max = 70 + self.lastchoice = -1 + + def highlight(self): + if self.lastchoice >= 0: + TEAMS[self.lastchoice].unhighlight() + self.iterations += 1 + if self.iterations >= self.max: + # Choosing time + self.lastchoice = -1 + TEAMS[-1].choose() + pygame.time.set_timer(HIGHLIGHTEVENT, 0) # Disable highlight + pygame.time.set_timer(CHOOSEEVENT, 5000, True) # make choice + self.iterations = 0 + else: + self.lastchoice = random.randrange(len(TEAMS)) + TEAMS[self.lastchoice].highlight() + + def draw_text(text, font, text_col, x, y): img = font.render(text, True, text_col) screen.blit(img, (x, y)) @@ -150,6 +183,8 @@ setup_team_board() random.shuffle(TEAMS) setup_subs() +HIGHLIGHTER = Highlighter() + while True: for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -160,17 +195,24 @@ while True: sys.exit() elif event.key == 115: TEAMS[5].highlight() - elif event.key == 32: # Spacebar + elif event.key == 100: # D for debug for sub in SUBS: if sub.team == "": sub.team = TEAMS.pop().team - elif event.key == 49: - team = TEAMS.pop() - SUBS[0].team = team.team - elif event.key == 50: - SUBS[1].team = TEAMS[random.randrange(len(TEAMS))].team - + elif event.key == 32: + pygame.time.set_timer(HIGHLIGHTEVENT, 100) # every 100ms print(event.key) + elif event.type == HIGHLIGHTEVENT: + HIGHLIGHTER.highlight() + elif event.type == CLEAREVENT: + for team in TEAMS: + team.unhighlight() + elif event.type == CHOOSEEVENT: + for sub in SUBS: + if sub.team == "": + sub.team = TEAMS.pop().team + pygame.time.set_timer(CLEAREVENT, 100, True) + break screen.blit(BGIMG, (0, 0))