aboutsummaryrefslogtreecommitdiff
path: root/src/splitscreen_duo/games/breakout.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/splitscreen_duo/games/breakout.py')
-rw-r--r--src/splitscreen_duo/games/breakout.py57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/splitscreen_duo/games/breakout.py b/src/splitscreen_duo/games/breakout.py
index 6a5e2cc..8506b75 100644
--- a/src/splitscreen_duo/games/breakout.py
+++ b/src/splitscreen_duo/games/breakout.py
@@ -124,6 +124,31 @@ class Breakout(GameBase):
return None
+ def draw_game(self, surface):
+ surface.fill(BLACK)
+ pygame.draw.rect(
+ surface,
+ BLUE,
+ [self.paddle[0], self.paddle[1], PADDLE_WIDTH, PADDLE_HEIGHT],
+ )
+ pygame.draw.circle(
+ surface,
+ WHITE,
+ [int(self.ball[0]), int(self.ball[1])],
+ BALL_SIZE,
+ )
+
+ for brick in self.bricks:
+ pygame.draw.rect(surface, RED, brick)
+
+ 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()
@@ -135,11 +160,10 @@ class Breakout(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 == "LEFT":
self.move_paddle(-20)
@@ -159,30 +183,7 @@ class Breakout(GameBase):
continue
- self.screen.fill(BLACK)
- pygame.draw.rect(
- self.screen,
- BLUE,
- [self.paddle[0], self.paddle[1], PADDLE_WIDTH, PADDLE_HEIGHT],
- )
- pygame.draw.circle(
- self.screen,
- WHITE,
- [int(self.ball[0]), int(self.ball[1])],
- BALL_SIZE,
- )
-
- for brick in self.bricks:
- pygame.draw.rect(self.screen, RED, brick)
-
- 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(60)