diff options
| author | Zoltan Szabatin <[email protected]> | 2025-05-14 21:36:56 -0700 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-05-14 21:36:56 -0700 |
| commit | 70a4c41a75275be6050683191e05ec1cb693ffce (patch) | |
| tree | ffa5257b21e227e17ab65d0ead0dd2851f22c97e /src/splitscreen_duo/games/snake.py | |
| parent | switched from usb hid to cdc (diff) | |
| download | splitscreen-duo-main.tar.xz splitscreen-duo-main.zip | |
Diffstat (limited to 'src/splitscreen_duo/games/snake.py')
| -rw-r--r-- | src/splitscreen_duo/games/snake.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/splitscreen_duo/games/snake.py b/src/splitscreen_duo/games/snake.py index 83ee987..11b66f7 100644 --- a/src/splitscreen_duo/games/snake.py +++ b/src/splitscreen_duo/games/snake.py @@ -17,12 +17,15 @@ logger = logging.getLogger(__name__) class Snake(GameBase): def __init__(self, screen, serial, instance, is_joint_mode=False): super().__init__(screen, serial, instance, is_joint_mode) - self.screen_width = screen.get_width() - self.screen_height = screen.get_height() self.reset() def reset(self): + global BLOCK_SIZE, SPEED + + min_dimension = min(self.screen_width, self.screen_height) + BLOCK_SIZE = max(10, min(20, min_dimension // 30)) + SPEED = 15 if self.screen_width >= 400 else 12 self.body = [ [ self.screen_width // 2 - self.screen_width // 2 % BLOCK_SIZE, @@ -143,7 +146,10 @@ class Snake(GameBase): if not self.is_joint_mode or self.instance != "primary": score_text = self.font.render(f"Score: {self.score}", True, WHITE) - self.screen.blit(score_text, (10, 10)) + if self.is_vertical: + self.screen.blit(score_text, (self.screen_width // 2 - score_text.get_width() // 2, 10)) + else: + self.screen.blit(score_text, (10, 10)) pygame.display.flip() clock.tick(SPEED) |