feat: improve game music

This commit is contained in:
Giovani
2021-07-08 11:23:47 -04:00
parent 68a24a5f4d
commit a9e5a1025c
14 changed files with 111 additions and 34 deletions

View File

@@ -6,6 +6,7 @@ from typing import List, Tuple
from types import FunctionType
from tetri5.util import ConfigurationManager
from tetri5.util import Controller
from tetri5.util import SoundManager
"""
TODO description
@@ -85,7 +86,6 @@ class Piece(Entity):
super().__init__(Piece._get_points(shape, position), color, border_color)
self._inner_border_color = inner_border_color
self._center = self._get_center(shape, position)
self._piece_set_sound = mixer.Channel(2)
self._previous_points = None
self._previous_center = None
@@ -118,6 +118,8 @@ class Piece(Entity):
self.rotate()
if well and self.collide(well) or stack and self.collide(stack):
self.revert()
else:
SoundManager.play_piece_rotate_sfx()
if Controller.key_down(pygame.K_LEFT):
self.move((-self._tile_size, 0))
if well and self.collide(well) or stack and self.collide(stack):
@@ -223,7 +225,7 @@ class Piece(Entity):
if self._current_set_time >= self._set_time:
self._current_set_time = 0
if self._entity_is_below(well) or self._entity_is_below(stack):
self._play_piece_set_sound()
SoundManager.play_piece_set_sfx()
stack.add_piece(self)
clear_current_piece()
else:
@@ -240,10 +242,6 @@ class Piece(Entity):
return mimic_points
def _play_piece_set_sound(self) -> None:
piece_set_sound_file = ConfigurationManager.get("sound", "piece-set")
self._piece_set_sound.play(mixer.Sound(piece_set_sound_file))
def _entity_is_below(self, entity: Entity) -> bool:
mimic_points = self._mimic_move((0, self._tile_size))
return entity and entity._collide(mimic_points)
@@ -275,7 +273,6 @@ class Stack(Entity):
super().__init__([], color, border_color)
self.total_lines = 0
self.lines_completed_last = 0
self.line_completed_sound = mixer.Channel(1)
def update(self, elapsed_time: int) -> None: # TODO remove scene argument
super().update(elapsed_time)
@@ -305,7 +302,11 @@ class Stack(Entity):
if not squares_to_exclude:
return 0
self._play_line_completed_sound()
if len(rows_completed) == 4:
SoundManager.play_four_lines_complete_sfx()
else:
SoundManager.play_line_complete_sfx()
new_points = []
for square in self._points:
if square not in squares_to_exclude:
@@ -314,17 +315,12 @@ class Stack(Entity):
vertex[1] <= row_completed
for row_completed in rows_completed
)
vertex[1] += self._tile_size * distance_to_move
new_points.append(square)
self._points = new_points
return len(rows_completed)
def _play_line_completed_sound(self) -> None:
line_completed_sound_file = ConfigurationManager.get("sound", "row-completion")
self.line_completed_sound.play(mixer.Sound(line_completed_sound_file))
"""
TODO description
"""