diff options
| author | Zoltan Szabatin <[email protected]> | 2025-05-14 22:08:14 -0700 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-05-14 22:08:14 -0700 |
| commit | b4d267c73293c6a46f4c85a07b415b6fe2b97251 (patch) | |
| tree | 4528f63bcdc0726ab10b26e072720f1e0ebb53d6 /src/splitscreen_duo/games/snake.py | |
| parent | feat: Split updates screen size (diff) | |
| download | splitscreen-duo-screen-orienting.tar.xz splitscreen-duo-screen-orienting.zip | |
feat: Screen rotation follows orientationscreen-orienting
Diffstat (limited to 'src/splitscreen_duo/games/snake.py')
| -rw-r--r-- | src/splitscreen_duo/games/snake.py | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/splitscreen_duo/games/snake.py b/src/splitscreen_duo/games/snake.py index 11b66f7..fe34143 100644 --- a/src/splitscreen_duo/games/snake.py +++ b/src/splitscreen_duo/games/snake.py @@ -94,6 +94,30 @@ class Snake(GameBase): or head in self.body[1:] ) + def draw_game(self, surface): + surface.fill(BLACK) + + for segment in self.body: + pygame.draw.rect( + surface, + GREEN, + [segment[0], segment[1], BLOCK_SIZE, BLOCK_SIZE], + ) + + pygame.draw.rect( + surface, + RED, + [self.food[0], self.food[1], BLOCK_SIZE, BLOCK_SIZE], + ) + + if not self.is_joint_mode or self.instance != "primary": + score_text = self.font.render(f"Score: {self.score}", True, WHITE) + + if self.is_vertical: + surface.blit(score_text, (self.screen_width // 2 - score_text.get_width() // 2, 10)) + else: + surface.blit(score_text, (10, 10)) + def main_loop(self): clock = pygame.time.Clock() @@ -105,11 +129,10 @@ class Snake(GameBase): if not (self.waiting or self.score_display_time): for event in pygame.event.get(): - result = self.handle_common_events(event) - action = self.input_handler.get_input(event) + action = self.handle_common_events(event) - if result is not None: - return result + if isinstance(action, dict) and action.get("command") is not None: + return action if action == "UP": self.change_to = "UP" @@ -125,32 +148,9 @@ class Snake(GameBase): if self.check_collision(): self.end_game(self.score) - continue - self.screen.fill(BLACK) - - for segment in self.body: - pygame.draw.rect( - self.screen, - GREEN, - [segment[0], segment[1], BLOCK_SIZE, BLOCK_SIZE], - ) - - pygame.draw.rect( - self.screen, - RED, - [self.food[0], self.food[1], BLOCK_SIZE, BLOCK_SIZE], - ) - - if not self.is_joint_mode or self.instance != "primary": - score_text = self.font.render(f"Score: {self.score}", True, WHITE) - - 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)) - + self.render_rotated(self.draw_game) pygame.display.flip() clock.tick(SPEED) |