summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcameltris.py17
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)