summaryrefslogtreecommitdiff
path: root/cameltris.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2020-12-22 21:58:40 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2020-12-22 21:58:40 +0100
commit86425f90b8f0b88819a8dafbb0c8aa5b55bc4d13 (patch)
treeb73581c61e3a17af87d9778f4c68769896dc2dc9 /cameltris.py
parent13de6c0cf24fd68d306a79ddaeed37415744e348 (diff)
Implement DAS mechanism
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'cameltris.py')
-rwxr-xr-xcameltris.py26
1 files changed, 21 insertions, 5 deletions
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: