diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-12-23 00:55:12 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-12-23 00:55:12 +0100 |
commit | 70d62ecc33078d43bd03ca5e4b0daaea1690d00e (patch) | |
tree | f4b8b8e5b99cbc1736d8f40f7337d8fd58ef9ebd /cameltris.py | |
parent | 55d3ae6c334fc6ee599d3b2e415ed1b4f81a48f7 (diff) |
Use argument parsing
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'cameltris.py')
-rwxr-xr-x | cameltris.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/cameltris.py b/cameltris.py index 7669dcf..8ece28d 100755 --- a/cameltris.py +++ b/cameltris.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import argparse import contextlib import enum import random @@ -318,6 +319,15 @@ def stick_piece(): next_piece, next_piece_position = generate_piece() refresh_piece_preview_canvas() +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() black = (0, 0, 0) @@ -364,10 +374,9 @@ das = 0 pressing_down_countdown = None -joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())] -for joystick in joysticks: +if ARGS["joystick_id"] is not None: + joystick = pygame.joystick.Joystick(ARGS["joystick_id"]) joystick.init() -joystick = joysticks[0] while True: piece_drop_frames += 1 |