]> git.mar77i.info Git - zenbook_gui/commitdiff
vs_memory: optimize for smaller screens
authormar77i <mar77i@protonmail.ch>
Sat, 15 Mar 2025 16:23:26 +0000 (17:23 +0100)
committermar77i <mar77i@protonmail.ch>
Sat, 15 Mar 2025 16:23:26 +0000 (17:23 +0100)
vs_memory/vs_memory.py

index c09cf5090f9c9d9b6ee49e7e1d0d32dba5ca1fa5..6620362d2d61950518f45ef4e609e07fdabb6447 100755 (executable)
@@ -32,7 +32,10 @@ class MemoryDestination(Child):
             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,
             )
 
 
@@ -80,16 +83,23 @@ class MemoryCard(Child):
 
 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"
@@ -109,26 +119,26 @@ class VSMemory(Root):
         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,
         )
@@ -137,7 +147,7 @@ class VSMemory(Root):
         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,
@@ -159,10 +169,9 @@ class VSMemory(Root):
         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: