feat: add ability to hard drop
This commit is contained in:
@@ -114,7 +114,7 @@ class Piece(Entity):
|
|||||||
self._applying_gravity = not self._applying_set
|
self._applying_gravity = not self._applying_set
|
||||||
|
|
||||||
# handle rotation, left and right movement
|
# handle rotation, left and right movement
|
||||||
if Controller.key_down(pygame.K_SPACE):
|
if Controller.key_down(pygame.K_UP):
|
||||||
self.rotate()
|
self.rotate()
|
||||||
if well and self.collide(well) or stack and self.collide(stack):
|
if well and self.collide(well) or stack and self.collide(stack):
|
||||||
self.revert()
|
self.revert()
|
||||||
@@ -141,6 +141,12 @@ class Piece(Entity):
|
|||||||
self._gravity_time = gravity_time - (level * gravity_increase)
|
self._gravity_time = gravity_time - (level * gravity_increase)
|
||||||
self._set_time = set_time
|
self._set_time = set_time
|
||||||
|
|
||||||
|
# handle hard drop
|
||||||
|
if Controller.key_down(pygame.K_SPACE):
|
||||||
|
self._points = self._get_ghost_piece_points(well, stack)
|
||||||
|
self._add_to_stack(stack, clear_current_piece)
|
||||||
|
|
||||||
|
|
||||||
def draw(self, surface: pygame.Surface, well: Well = None, stack: "Stack" = None) -> None:
|
def draw(self, surface: pygame.Surface, well: Well = None, stack: "Stack" = None) -> None:
|
||||||
# ghost piece
|
# ghost piece
|
||||||
if well and stack:
|
if well and stack:
|
||||||
@@ -225,13 +231,16 @@ class Piece(Entity):
|
|||||||
if self._current_set_time >= self._set_time:
|
if self._current_set_time >= self._set_time:
|
||||||
self._current_set_time = 0
|
self._current_set_time = 0
|
||||||
if self._entity_is_below(well) or self._entity_is_below(stack):
|
if self._entity_is_below(well) or self._entity_is_below(stack):
|
||||||
SoundManager.play_piece_set_sfx()
|
self._add_to_stack(stack, clear_current_piece)
|
||||||
stack.add_piece(self)
|
|
||||||
clear_current_piece()
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _add_to_stack(self, stack: "Stack", clear_current_piece: FunctionType) -> None:
|
||||||
|
SoundManager.play_piece_set_sfx()
|
||||||
|
stack.add_piece(self)
|
||||||
|
clear_current_piece()
|
||||||
|
|
||||||
def _mimic_move(self, vector: Tuple) -> List:
|
def _mimic_move(self, vector: Tuple) -> List:
|
||||||
mimic_points = copy.deepcopy(self._points)
|
mimic_points = copy.deepcopy(self._points)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user