mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): add drop timer
This commit is contained in:
parent
a56f457482
commit
e77dce308b
@ -285,6 +285,7 @@ class Tetris(BaseScreen):
|
||||
Timer(self.initial_block_speed, True, self.move_down),
|
||||
Timer(CONFIG.game.movment_delay),
|
||||
Timer(CONFIG.game.rotation_delay),
|
||||
Timer(CONFIG.game.drop_delay),
|
||||
)
|
||||
self.timers.vertical.activate()
|
||||
|
||||
@ -293,6 +294,7 @@ class Tetris(BaseScreen):
|
||||
self.initial_block_speed = CONFIG.game.initial_speed
|
||||
self.increased_block_speed = self.initial_block_speed * 0.4
|
||||
self.down_pressed = False
|
||||
self.drop_pressed = False
|
||||
self.level: int = 1
|
||||
self.score: int = 0
|
||||
self.lines: int = 0
|
||||
@ -351,6 +353,7 @@ class Tetris(BaseScreen):
|
||||
counter_clockwise_keys = (
|
||||
keys[pygame.K_e] or keys[pygame.K_i] or keys[pygame.K_LEFT]
|
||||
)
|
||||
|
||||
if not self.timers.rotation.active:
|
||||
if clockwise_keys:
|
||||
self.rotate()
|
||||
@ -375,8 +378,9 @@ class Tetris(BaseScreen):
|
||||
"""Handle the drop key [K_SPACE]."""
|
||||
drop_keys = keys[pygame.K_SPACE]
|
||||
|
||||
if drop_keys:
|
||||
if not self.timers.drop.active and drop_keys:
|
||||
self.drop()
|
||||
self.timers.drop.activate()
|
||||
|
||||
def _reset_game_state(self) -> None:
|
||||
"""Reset the game state."""
|
||||
|
||||
@ -63,8 +63,10 @@ class Timers(NamedTuple):
|
||||
vertical: Timer for vertical movement.
|
||||
horizontal: Timer for horizontal movement.
|
||||
rotation: Timer for rotation.
|
||||
drop: Timer for dropping.
|
||||
"""
|
||||
|
||||
vertical: Timer
|
||||
horizontal: Timer
|
||||
rotation: Timer
|
||||
drop: Timer
|
||||
|
||||
@ -21,9 +21,10 @@ class Game:
|
||||
size: Size = Size(columns * cell.width, rows * cell.width)
|
||||
pos: Vec2 = Vec2(padding, padding)
|
||||
offset: Vec2 = Vec2(columns // 2, -1)
|
||||
initial_speed: float | int = 200
|
||||
movment_delay: int = 200
|
||||
initial_speed: float | int = 300
|
||||
movment_delay: int = 100
|
||||
rotation_delay: int = 200
|
||||
drop_delay: int = 200
|
||||
score: dict[int, int] = {1: 40, 2: 100, 3: 300, 4: 1200}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user