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.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/splitscreen_duo/games/benchmark.py b/src/splitscreen_duo/games/benchmark.py
new file mode 100644
index 0000000..3c8ea81
--- /dev/null
+++ b/src/splitscreen_duo/games/benchmark.py
@@ -0,0 +1,65 @@
+import pygame
+import random
+
+from splitscreen_duo.command import Command
+
+BLACK = (0, 0, 0)
+WHITE = (255, 255, 255)
+BALL_SIZE = 25
+
+
+class Ball:
+ def __init__(self, screen_width, screen_height):
+ self.x = random.randrange(BALL_SIZE, screen_width - BALL_SIZE)
+ self.y = random.randrange(BALL_SIZE, screen_height - BALL_SIZE)
+ self.change_x = random.randrange(-2, 3)
+ self.change_y = random.randrange(-2, 3)
+
+
+def main_loop(screen, serial):
+ clock = pygame.time.Clock()
+ ball_list = []
+ balls = 1
+ ball = Ball(screen.get_width(), screen.get_height())
+ is_running = True
+
+ ball_list.append(ball)
+
+ while is_running:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ return {"command": Command.QUIT.value, "action": None, "value": None}
+
+ elif event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_SPACE:
+ balls = balls * 2
+
+ for _ in range(balls - 1):
+ ball = Ball(screen.get_width(), screen.get_height())
+
+ ball_list.append(ball)
+
+ elif event.key == pygame.K_ESCAPE:
+ return None
+
+ for ball in ball_list:
+ ball.x += ball.change_x
+ ball.y += ball.change_y
+
+ if ball.y > screen.get_height() - BALL_SIZE or ball.y < BALL_SIZE:
+ ball.change_y *= -1
+
+ if ball.x > screen.get_width() - BALL_SIZE or ball.x < BALL_SIZE:
+ ball.change_x *= -1
+
+ screen.fill(BLACK)
+
+ for ball in ball_list:
+ pygame.draw.circle(screen, WHITE, [int(ball.x), int(ball.y)], BALL_SIZE)
+
+ pygame.display.flip()
+ # clock.tick(60)
+ clock.tick()
+ # print(f"fps: {clock.get_fps():.2f}, balls: {balls}")
+
+ return None