From adf005bd29a395b653df1d990aa72694360a11dc Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 12 Nov 2021 13:32:37 +0100 Subject: Rename the package cameltris and provide __main__.py Signed-off-by: Olivier Gayot --- __main__.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 __main__.py (limited to '__main__.py') diff --git a/__main__.py b/__main__.py new file mode 100755 index 0000000..e823054 --- /dev/null +++ b/__main__.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +import argparse + +import pygame + +from cameltris.controller import Controller, KeyboardController, JoystickController +from cameltris.screens.Screen import Screen +from cameltris.screens.InGame import InGame as InGameScreen, Player +from cameltris.screens.Pause import Pause as PauseScreen +from cameltris.misc import Pause, UnPause + + +PARSER = argparse.ArgumentParser() + +PARSER.add_argument("--starting-level", type=int, choices=list(range(1, 30)), default=1) +PARSER.add_argument("--joystick", type=int, dest="joystick_id", metavar="Joystick ID") + +ARGS = vars(PARSER.parse_args()) + +print(ARGS) + +pygame.init() + +screen = pygame.display.set_mode((801, 1000)) + +controller: Controller +if ARGS["joystick_id"] is not None: + joystick = pygame.joystick.Joystick(ARGS["joystick_id"]) + joystick.init() + controller = JoystickController(joystick) +else: + controller = KeyboardController(pygame.key) + +# Just one player +players = [Player(controller, ARGS["starting_level"])] + +for player in players: + player.refresh_piece_preview_canvas() + +clock = pygame.time.Clock() + +current_screen: Screen +current_screen = ingame_screen = InGameScreen(players, screen) + +while True: + try: + current_screen.oneframe() + except Pause: + current_screen = PauseScreen(screen) + except UnPause: + current_screen = ingame_screen + + current_screen.refresh() + pygame.display.update() + + clock.tick(60) -- cgit v1.2.3