From 86425f90b8f0b88819a8dafbb0c8aa5b55bc4d13 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 22 Dec 2020 21:58:40 +0100 Subject: Implement DAS mechanism Signed-off-by: Olivier Gayot --- cameltris.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'cameltris.py') diff --git a/cameltris.py b/cameltris.py index 63c8735..1458a99 100755 --- a/cameltris.py +++ b/cameltris.py @@ -339,16 +339,16 @@ refresh_piece_preview_canvas() frames_per_gridcell = [48, 43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1] piece_drop_frames = 0 -level = 1 +starting_level = level = 1 score = 0 -pygame.key.set_repeat(200, 50) - clock = pygame.time.Clock() print("Level is ", level) lines_burnt = 0 +das = 0 + while True: piece_drop_frames += 1 @@ -359,23 +359,39 @@ while True: if event.key in (pygame.K_ESCAPE, pygame.K_q): sys.exit() with contextlib.suppress(WouldCollide): - if event.key in (pygame.K_UP, pygame.K_k): - move_piece_up() if event.key in (pygame.K_RIGHT, pygame.K_l): move_piece_right() + das = 0 if event.key in (pygame.K_LEFT, pygame.K_h): move_piece_left() + das = 0 if event.key == pygame.K_s: rotate_piece_clockwise() if event.key == pygame.K_d: rotate_piece_counter_clockwise() if event.key in (pygame.K_DOWN, pygame.K_j): piece_drop_frames = 0 + das = 0 try: move_piece_down() except WouldCollide: stick_piece() + das += 1 + if das == 16: + pressed_keys = pygame.key.get_pressed() + with contextlib.suppress(WouldCollide): + if pressed_keys[pygame.K_RIGHT] or pressed_keys[pygame.K_l]: + move_piece_right() + if pressed_keys[pygame.K_LEFT] or pressed_keys[pygame.K_h]: + move_piece_left() + if pressed_keys[pygame.K_DOWN] or pressed_keys[pygame.K_j]: + try: + move_piece_down() + except WouldCollide: + stick_piece() + das = 10 + if piece_drop_frames >= frames_per_gridcell[level - 1]: piece_drop_frames = 0 try: -- cgit v1.2.3