summaryrefslogtreecommitdiff
path: root/cameltris.py
diff options
context:
space:
mode:
Diffstat (limited to 'cameltris.py')
-rwxr-xr-xcameltris.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/cameltris.py b/cameltris.py
index 959ef37..5ee7984 100755
--- a/cameltris.py
+++ b/cameltris.py
@@ -268,12 +268,19 @@ grid = [[None for _ in range(10)] for _ in range(20)]
current_piece, current_piece_position = generate_piece()
next_piece, next_piece_position = generate_piece()
-drop_rate = 100
+refresh_piece_preview_canvas()
+
+# Number of frames
+frames_per_gridcell = 3
+piece_drop_frames = 0
pygame.key.set_repeat(200, 50)
-pygame.time.set_timer(pygame.USEREVENT, drop_rate, True)
+
+clock = pygame.time.Clock()
while True:
+ piece_drop_frames += 1
+
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
@@ -292,17 +299,20 @@ while True:
if event.key == pygame.K_d:
rotate_piece_counter_clockwise()
if event.key in (pygame.K_DOWN, pygame.K_j):
+ piece_drop_frames = 0
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)
+
+ if piece_drop_frames >= frames_per_gridcell:
+ piece_drop_frames = 0
+ try:
+ move_piece_down()
+ except WouldCollide:
+ stick_piece()
refresh_screen()
- pygame.display.flip()
+ pygame.display.update()
+
+ clock.tick(60)