Browse Source

Animates team selection

master
bertieb 4 years ago
committed by Rob Hallam
parent
commit
6256ed2270
1 changed files with 49 additions and 7 deletions
  1. +49
    -7
      teampicker.py

+ 49
- 7
teampicker.py View File

@@ -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))



Loading…
Cancel
Save