diff options
| author | Zoltan Szabatin <[email protected]> | 2025-03-02 22:39:48 -0800 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-03-02 22:39:48 -0800 |
| commit | 05061161e296ba2e54f3fc7d60a88adac9cd2761 (patch) | |
| tree | 20c3c64cb254ff08ca183c880293d434d686fc32 /src/splitscreen_duo/games/pong.py | |
| parent | feat(games): Use input handler (diff) | |
| download | splitscreen-duo-05061161e296ba2e54f3fc7d60a88adac9cd2761.tar.xz splitscreen-duo-05061161e296ba2e54f3fc7d60a88adac9cd2761.zip | |
feat: Add split mode toggle for debugging
Diffstat (limited to 'src/splitscreen_duo/games/pong.py')
| -rw-r--r-- | src/splitscreen_duo/games/pong.py | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/src/splitscreen_duo/games/pong.py b/src/splitscreen_duo/games/pong.py index 7f0d4e9..464e529 100644 --- a/src/splitscreen_duo/games/pong.py +++ b/src/splitscreen_duo/games/pong.py @@ -17,9 +17,8 @@ logger = logging.getLogger(__name__) class Pong(GameBase): - def __init__(self, screen, serial, instance): - super().__init__(screen, serial, instance) - + 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.player_score = 0 @@ -33,14 +32,8 @@ class Pong(GameBase): self.screen_width // 2 - PADDLE_WIDTH // 2, self.screen_height - 40, ] - self.ai_paddle = [ - self.screen_width // 2 - PADDLE_WIDTH // 2, - 40, - ] - self.ball = [ - self.screen_width // 2, - self.screen_height // 2, - ] + self.ai_paddle = [self.screen_width // 2 - PADDLE_WIDTH // 2, 40] + self.ball = [self.screen_width // 2, self.screen_height // 2] self.ball_dx = random.choice([-BALL_SPEED, BALL_SPEED]) self.ball_dy = BALL_SPEED @@ -61,6 +54,7 @@ class Pong(GameBase): if self.ai_paddle[0] < 0: self.ai_paddle[0] = 0 + if self.ai_paddle[0] > self.screen_width - PADDLE_WIDTH: self.ai_paddle[0] = self.screen_width - PADDLE_WIDTH @@ -72,16 +66,10 @@ class Pong(GameBase): self.ball_dx *= -1 player_rect = pygame.Rect( - self.player_paddle[0], - self.player_paddle[1], - PADDLE_WIDTH, - PADDLE_HEIGHT, + self.player_paddle[0], self.player_paddle[1], PADDLE_WIDTH, PADDLE_HEIGHT ) ai_rect = pygame.Rect( - self.ai_paddle[0], - self.ai_paddle[1], - PADDLE_WIDTH, - PADDLE_HEIGHT, + self.ai_paddle[0], self.ai_paddle[1], PADDLE_WIDTH, PADDLE_HEIGHT ) ball_rect = pygame.Rect( self.ball[0] - BALL_SIZE, @@ -102,17 +90,16 @@ class Pong(GameBase): if self.ball[1] <= 0: self.player_score += 1 + self.send_stats(self.player_score) self.reset_ball() elif self.ball[1] >= self.screen_height: self.ai_score += 1 + self.send_stats(self.player_score) self.reset_ball() def reset_ball(self): - self.ball = [ - self.screen_width // 2, - self.screen_height // 2, - ] + self.ball = [self.screen_width // 2, self.screen_height // 2] self.ball_dx = random.choice([-BALL_SPEED, BALL_SPEED]) self.ball_dy = random.choice([-BALL_SPEED, BALL_SPEED]) @@ -201,9 +188,10 @@ class Pong(GameBase): game_over = self.check_game_over() if game_over: - self.score_display_time = pygame.time.get_ticks() + if self.is_joint_mode and self.instance == "primary": + self.send_stats(self.player_score) - logger.debug(f"game over: {game_over}, starting score display") + self.end_game(self.player_score) continue @@ -230,13 +218,17 @@ class Pong(GameBase): BALL_SIZE, ) - player_score_text = self.font.render( - f"Player: {self.player_score}", True, WHITE - ) - ai_score_text = self.font.render(f"AI: {self.ai_score}", True, WHITE) + if not self.is_joint_mode or self.instance != "primary": + player_score_text = self.font.render( + f"Player: {self.player_score}", True, WHITE + ) + ai_score_text = self.font.render( + f"AI: {self.ai_score}", True, WHITE + ) + + self.screen.blit(player_score_text, (10, self.screen_height - 40)) + self.screen.blit(ai_score_text, (10, 10)) - self.screen.blit(player_score_text, (10, self.screen_height - 40)) - self.screen.blit(ai_score_text, (10, 10)) pygame.display.flip() clock.tick(60) |