self.surf.blit(self.team.logo, self.rect.topleft)
else:
pygame.draw.rect(
- self.surf, "red" if self.highlight else "dimgray", self.rect, 16
+ self.surf,
+ "red" if self.highlight else "dimgray",
+ self.rect.inflate(-4, -4),
+ 16,
)
class VSMemory(Root):
BACKGROUND_COLOR = "black"
- MEMORY_RECT = pygame.Rect((640, 384), (512, 1190))
+ TOP = 186
+ LEFT = 256
+ MEMORY_LEFT = 640
+ #MEMORY_RECT = pygame.Rect((640, 184), (512, 896))
NUMBER_REGEX = re.compile(r"[-+]?\d*(\.\d+)?")
def get_memory_destinations(self):
height = self.surf.get_height()
- y_cell = (height - 384) // (len(self.teams) // 2 + 1)
+ y_cell = (height - self.TOP) // (len(self.teams) // 2)
for y in range(len(self.teams) // 2):
- y = 384 + y * y_cell
- yield MemoryDestination(self, pygame.Rect((256, y), (128, 128)), False)
- yield MemoryDestination(self, pygame.Rect((512, y), (128, 128)), False)
+ y = self.TOP + y * y_cell
+ yield MemoryDestination(
+ self, pygame.Rect((self.LEFT, y), (128, 128)), False
+ )
+ yield MemoryDestination(
+ self, pygame.Rect((self.LEFT + 256, y), (128, 128)), False
+ )
def get_score(self):
return f"Score: {self.failed} failed, {self.successful} successful"
self.successful = 0
self.score = Label(
self,
- pygame.Rect((256, 192), (512, 128)),
+ pygame.Rect((self.LEFT, 28), (512, 128)),
self.get_score(),
)
self.start_button = Button(
self,
- pygame.Rect((256, 384), (256, 192)),
+ pygame.Rect((self.LEFT, self.TOP), (256, 192)),
"Start",
self.start_round,
True,
)
self.look_timeout_input = TextInput(
self,
- pygame.Rect((640, 416), (512, 128)),
+ pygame.Rect((640, 216), (512, 128)),
self.set_look_timeout,
str(self.look_timeout),
self.NUMBER_REGEX.fullmatch,
)
self.end_round_button = Button(
self,
- pygame.Rect((768, self.surf.get_height() // 2 - 128), (256, 256)),
+ pygame.Rect((768, self.surf.get_height() // 2 - 128), (256, 192)),
"End",
self.end_round,
)
self.memory_cards = tuple(
MemoryCard(
self,
- pygame.Rect(self.MEMORY_RECT.topleft, (128, 128)),
+ pygame.Rect((self.MEMORY_LEFT, self.TOP), (128, 128)),
team,
self.drop_card,
False,
self.started_timer = time()
self.dirty = True
- @classmethod
- def place_memory_card(cls, rect):
- rect.left = cls.MEMORY_RECT.left + randbelow(cls.MEMORY_RECT.width - rect.width)
- rect.top = cls.MEMORY_RECT.top + randbelow(cls.MEMORY_RECT.height - rect.height)
+ def place_memory_card(self, rect):
+ rect.left = self.MEMORY_LEFT + randbelow(512 - rect.width)
+ rect.top = self.TOP + randbelow(self.surf.get_height() - self.TOP - rect.height)
def interactive_round(self):
for child in self.memory_destinations: