diff options
| author | Zoltan Szabatin <[email protected]> | 2025-02-25 15:46:11 -0800 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-02-25 15:46:11 -0800 |
| commit | 442b376c6688e2a564e6ddc549da192406fe09f4 (patch) | |
| tree | 50aa1710a9c44012ea3ff26fc5999d067859baeb /src/splitscreen_duo/menu.py | |
| parent | chore: Create justfile for serial port tasks (diff) | |
| download | splitscreen-duo-442b376c6688e2a564e6ddc549da192406fe09f4.tar.xz splitscreen-duo-442b376c6688e2a564e6ddc549da192406fe09f4.zip | |
feat: Add Pygame menu
Diffstat (limited to 'src/splitscreen_duo/menu.py')
| -rw-r--r-- | src/splitscreen_duo/menu.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/splitscreen_duo/menu.py b/src/splitscreen_duo/menu.py new file mode 100644 index 0000000..489a75c --- /dev/null +++ b/src/splitscreen_duo/menu.py @@ -0,0 +1,64 @@ +import sys +import pygame +import os +from .input import Input + +pygame.init() +pygame.display.set_caption("SplitScreen Duo Menu") + +WIDTH, HEIGHT = ( + pygame.display.Info().current_w // 2, + pygame.display.Info().current_h // 2, +) +WHITE = (255, 255, 255) +BLACK = (0, 0, 0) +FONT = pygame.font.Font(None, 36) +IS_DEVELOPMENT_MODE = os.environ.get("DEVELOPMENT", "").lower() +OPTIONS = ["Breakout", "Pong v.s. Computer", "Snake", "Quit"] +selected_index = 0 +screen = pygame.display.set_mode( + (WIDTH, HEIGHT) if IS_DEVELOPMENT_MODE else (0, 0), + 0 if IS_DEVELOPMENT_MODE else pygame.FULLSCREEN, +) + + +def draw_menu(): + screen.fill(WHITE) + + for i, option in enumerate(OPTIONS): + text = FONT.render(option, True, BLACK if i != selected_index else (200, 0, 0)) + + screen.blit(text, (WIDTH // 2 - text.get_width() // 2, 150 + i * 50)) + + pygame.display.flip() + + +def main_loop(): + global selected_index + + is_running = True + input_handler = Input(debug=IS_DEVELOPMENT_MODE) + + while is_running: + draw_menu() + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + + action = input_handler.get_input(event) + + if action == "UP": + selected_index = (selected_index - 1) % len(OPTIONS) + elif action == "DOWN": + selected_index = (selected_index + 1) % len(OPTIONS) + elif action == "SELECT": + if OPTIONS[selected_index] == "Quit": + pygame.quit() + sys.exit() + else: + print(OPTIONS[selected_index]) + elif action == "QUIT": + pygame.quit() + sys.exit() |