diff options
Diffstat (limited to 'src/splitscreen_duo/games/benchmark.py')
| -rw-r--r-- | src/splitscreen_duo/games/benchmark.py | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/src/splitscreen_duo/games/benchmark.py b/src/splitscreen_duo/games/benchmark.py index efe48c3..13b14f7 100644 --- a/src/splitscreen_duo/games/benchmark.py +++ b/src/splitscreen_duo/games/benchmark.py @@ -1,10 +1,12 @@ import pygame import random +import os from splitscreen_duo.command import Command BLACK = (0, 0, 0) WHITE = (255, 255, 255) +ROTATION_ENABLED = os.getenv("DEVELOPMENT", "") in ["", "0"] BALL_SIZE = 25 @@ -16,10 +18,34 @@ class Ball: self.change_y = random.randrange(-2, 3) +def draw_game(surface, ball_list, fps, balls, is_vertical, screen_width, screen_height): + surface.fill(BLACK) + + for ball in ball_list: + pygame.draw.circle(surface, WHITE, [int(ball.x), int(ball.y)], BALL_SIZE) + + fps_text = pygame.font.render(f"FPS: {fps:.1f}", True, WHITE) + ball_text = pygame.font.render(f"Balls: {balls}", True, WHITE) + + if is_vertical: + surface.blit(fps_text, (screen_width // 2 - fps_text.get_width() // 2, 10)) + surface.blit(ball_text, (screen_width // 2 - ball_text.get_width() // 2, 40)) + else: + surface.blit(fps_text, (10, 10)) + surface.blit(ball_text, (10, 40)) + def main_loop(screen, serial): clock = pygame.time.Clock() screen_width = screen.get_width() screen_height = screen.get_height() + instance = os.getenv("INSTANCE", "Unknown") + rotation_angle = 0 + + if ROTATION_ENABLED: + if instance == "primary": + rotation_angle = 90 # Right is down + elif instance == "secondary": + rotation_angle = -90 # Left is down global BALL_SIZE @@ -76,21 +102,23 @@ def main_loop(screen, serial): if b.y > screen_height - BALL_SIZE: b.y = screen_height - BALL_SIZE - screen.fill(BLACK) + fps = clock.get_fps() - for ball in ball_list: - pygame.draw.circle(screen, WHITE, [int(ball.x), int(ball.y)], BALL_SIZE) + if ROTATION_ENABLED and rotation_angle != 0 and not is_vertical: + render_surface = pygame.Surface((screen_width, screen_height)) - fps = clock.get_fps() - fps_text = font.render(f"FPS: {fps:.1f}", True, WHITE) - ball_text = font.render(f"Balls: {balls}", True, WHITE) + draw_game(render_surface, ball_list, fps, balls, is_vertical, screen_width, screen_height) + + rotated = pygame.transform.rotate(render_surface, rotation_angle) + + screen.fill(BLACK) + + pos_x = (screen_width - rotated.get_width()) // 2 + pos_y = (screen_height - rotated.get_height()) // 2 - if is_vertical: - screen.blit(fps_text, (screen_width // 2 - fps_text.get_width() // 2, 10)) - screen.blit(ball_text, (screen_width // 2 - ball_text.get_width() // 2, 40)) + screen.blit(rotated, (pos_x, pos_y)) else: - screen.blit(fps_text, (10, 10)) - screen.blit(ball_text, (10, 40)) + draw_game(screen, ball_list, fps, balls, is_vertical, screen_width, screen_height) pygame.display.flip() # clock.tick(60) |