summaryrefslogtreecommitdiff
path: root/cameltris.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2020-12-22 22:20:32 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2020-12-22 22:20:32 +0100
commitceee983259dea1f5d478cabd78223450d06d209b (patch)
tree09e7ad256339909694c73c92f118846a7f09e054 /cameltris.py
parent86425f90b8f0b88819a8dafbb0c8aa5b55bc4d13 (diff)
Implement pressing down correctly
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'cameltris.py')
-rwxr-xr-xcameltris.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/cameltris.py b/cameltris.py
index 1458a99..0b0aa7e 100755
--- a/cameltris.py
+++ b/cameltris.py
@@ -349,6 +349,8 @@ lines_burnt = 0
das = 0
+pressing_down_countdown = None
+
while True:
piece_drop_frames += 1
@@ -371,11 +373,14 @@ while True:
rotate_piece_counter_clockwise()
if event.key in (pygame.K_DOWN, pygame.K_j):
piece_drop_frames = 0
- das = 0
+ pressing_down_countdown = 3
try:
move_piece_down()
except WouldCollide:
stick_piece()
+ elif event.type == pygame.KEYUP:
+ if event.key in (pygame.K_DOWN, pygame.K_j):
+ pressing_down_countdown = None
das += 1
if das == 16:
@@ -385,13 +390,17 @@ while True:
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 pressing_down_countdown == 0:
+ try:
+ move_piece_down()
+ except WouldCollide:
+ stick_piece()
+ pressing_down_countdown = 2
+ elif pressing_down_countdown is not None:
+ pressing_down_countdown -= 1
+
if piece_drop_frames >= frames_per_gridcell[level - 1]:
piece_drop_frames = 0
try: