diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-12-21 23:50:04 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-12-21 23:50:04 +0100 |
commit | f4e3c5e10adc9f612d91282911b4c9cbd2921943 (patch) | |
tree | 62ecd45c78f6e895e88aec9a0d6eb0689e872a3f | |
parent | de3c3da845443880d8e87d56e47e77c9b5019e79 (diff) |
Drop pieces automatically and enable keyboard repeat
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rwxr-xr-x | cameltris.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cameltris.py b/cameltris.py index 1246b4e..f17c872 100755 --- a/cameltris.py +++ b/cameltris.py @@ -229,6 +229,11 @@ grid = [[None for _ in range(10)] for _ in range(20)] current_piece, current_piece_position = generate_piece() +drop_rate = 100 + +pygame.key.set_repeat(200, 50) +pygame.time.set_timer(pygame.USEREVENT, drop_rate, True) + while True: for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -247,12 +252,18 @@ while True: rotate_piece_clockwise() if event.key == pygame.K_d: rotate_piece_counter_clockwise() - try: if event.key in (pygame.K_DOWN, pygame.K_j): - move_piece_down() + try: + move_piece_down() + except WouldCollide: + stick_piece() + pygame.time.set_timer(pygame.USEREVENT, drop_rate, True) + elif event.type == pygame.USEREVENT: + try: + move_piece_down() except WouldCollide: stick_piece() + pygame.time.set_timer(pygame.USEREVENT, drop_rate, True) refresh_screen() pygame.display.flip() - time.sleep(.1) |