aboutsummaryrefslogtreecommitdiff
path: root/src/splitscreen_duo/games/benchmark.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/splitscreen_duo/games/benchmark.py')
-rw-r--r--src/splitscreen_duo/games/benchmark.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/splitscreen_duo/games/benchmark.py b/src/splitscreen_duo/games/benchmark.py
index 3c8ea81..efe48c3 100644
--- a/src/splitscreen_duo/games/benchmark.py
+++ b/src/splitscreen_duo/games/benchmark.py
@@ -18,10 +18,18 @@ class Ball:
def main_loop(screen, serial):
clock = pygame.time.Clock()
+ screen_width = screen.get_width()
+ screen_height = screen.get_height()
+
+ global BALL_SIZE
+
+ BALL_SIZE = max(15, min(25, min(screen_width, screen_height) // 20))
+ is_vertical = screen_height > screen_width * 1.5
ball_list = []
balls = 1
- ball = Ball(screen.get_width(), screen.get_height())
+ ball = Ball(screen_width, screen_height)
is_running = True
+ font = pygame.font.Font(None, 36)
ball_list.append(ball)
@@ -52,11 +60,38 @@ def main_loop(screen, serial):
if ball.x > screen.get_width() - BALL_SIZE or ball.x < BALL_SIZE:
ball.change_x *= -1
+ current_width = screen.get_width()
+ current_height = screen.get_height()
+
+ if current_width != screen_width or current_height != screen_height:
+ screen_width = current_width
+ screen_height = current_height
+ BALL_SIZE = max(15, min(25, min(screen_width, screen_height) // 20))
+ is_vertical = screen_height > screen_width * 1.5
+
+ for b in ball_list:
+ if b.x > screen_width - BALL_SIZE:
+ b.x = screen_width - BALL_SIZE
+
+ if b.y > screen_height - BALL_SIZE:
+ b.y = screen_height - BALL_SIZE
+
screen.fill(BLACK)
for ball in ball_list:
pygame.draw.circle(screen, WHITE, [int(ball.x), int(ball.y)], BALL_SIZE)
+ fps = clock.get_fps()
+ fps_text = font.render(f"FPS: {fps:.1f}", True, WHITE)
+ ball_text = font.render(f"Balls: {balls}", True, WHITE)
+
+ 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))
+ else:
+ screen.blit(fps_text, (10, 10))
+ screen.blit(ball_text, (10, 40))
+
pygame.display.flip()
# clock.tick(60)
clock.tick()