feat: add the rest of the sounds with channels
This commit is contained in:
11
Tetris.py
11
Tetris.py
@@ -7,7 +7,7 @@ from util.PieceGenerator import PieceGenerator
|
||||
from entity.Well import Well
|
||||
from entity.Stack import Stack
|
||||
|
||||
# TODO should be a singleton?
|
||||
# TODO should be a singleton and refactor the whole file?
|
||||
class Tetris:
|
||||
|
||||
def __init__(self):
|
||||
@@ -15,6 +15,7 @@ class Tetris:
|
||||
self.tile_size = -1
|
||||
self.screen = None
|
||||
self.clock = None
|
||||
self.main_music = None
|
||||
self.current_piece = None
|
||||
self.well = None
|
||||
self.stack = None
|
||||
@@ -32,15 +33,17 @@ class Tetris:
|
||||
self.tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||
self.screen = pygame.display.set_mode((win_width, win_height))
|
||||
self.clock = pygame.time.Clock()
|
||||
mixer.music.load("main_music.mp3")
|
||||
mixer.music.set_volume(0.7)
|
||||
self.main_music = mixer.Channel(0)
|
||||
self.well = Well((280, 80), ConfigurationManager.configuration["color"]["border"]) # TODO calculate position later and redo color config for well
|
||||
self.stack = Stack(ConfigurationManager.configuration["color"]["base-4"], ConfigurationManager.configuration["color"]["border"])
|
||||
|
||||
loaded_icon = pygame.image.load(win_icon)
|
||||
pygame.display.set_caption(win_title)
|
||||
pygame.display.set_icon(loaded_icon)
|
||||
mixer.music.play(-1)
|
||||
|
||||
main_music_file = ConfigurationManager.configuration["sound"]["main-music"]
|
||||
self.main_music.set_volume(0.7)
|
||||
self.main_music.play(mixer.Sound(main_music_file), -1)
|
||||
|
||||
# gets called from the games main loop
|
||||
def update(self) -> None:
|
||||
|
||||
@@ -5,6 +5,11 @@ window:
|
||||
title: "Tetris"
|
||||
bg-color: "#6495ED" # cornflower-blue
|
||||
|
||||
sound:
|
||||
main-music: "main_music.ogg"
|
||||
row-completion: "row_completion.wav"
|
||||
piece-set: "piece_set_3.wav"
|
||||
|
||||
engine:
|
||||
fps: 60
|
||||
tile-size: 20
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import List, Tuple
|
||||
from pygame import mixer
|
||||
import copy
|
||||
|
||||
from entity.Entity import Entity
|
||||
@@ -15,6 +16,7 @@ class Piece(Entity):
|
||||
def __init__(self, shape: Tuple, position: Tuple, color: str, border_color: str):
|
||||
super().__init__(self.__get_points(shape, position), color, border_color)
|
||||
self.center = self.__get_center(shape, position)
|
||||
self.piece_set_sound = mixer.Channel(2)
|
||||
|
||||
self.previous_points = None
|
||||
self.previous_center = None
|
||||
@@ -72,6 +74,11 @@ class Piece(Entity):
|
||||
self.points = self.previous_points
|
||||
self.center = self.previous_center
|
||||
|
||||
# TODO should be private
|
||||
def play_piece_set_sound(self) -> None:
|
||||
piece_set_sound_file = ConfigurationManager.configuration["sound"]["rpiece-set"]
|
||||
self.piece_set_sound.play(mixer.Sound(piece_set_sound_file))
|
||||
|
||||
def __get_points(self, shape: Tuple, position: Tuple) -> List:
|
||||
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from pygame import mixer
|
||||
|
||||
from util.ConfigurationManager import ConfigurationManager
|
||||
from entity.Piece import Piece
|
||||
from entity.Well import Well
|
||||
@@ -8,6 +10,7 @@ class Stack(Entity):
|
||||
def __init__(self, color: str, border_color: str):
|
||||
super().__init__([], color, border_color)
|
||||
self.rows_completed_count = 0
|
||||
self.row_completion_sound = mixer.Channel(1)
|
||||
|
||||
def update(self, elapsed_time) -> None:
|
||||
super().update(elapsed_time)
|
||||
@@ -48,4 +51,9 @@ class Stack(Entity):
|
||||
new_points.append(square)
|
||||
self.points = new_points
|
||||
|
||||
self.__play_row_completion_sound()
|
||||
return len(rows_completed)
|
||||
|
||||
def __play_row_completion_sound(self) -> None:
|
||||
row_completion_sound_file = ConfigurationManager.configuration["sound"]["row-completion"]
|
||||
self.row_completion_sound.play(mixer.Sound(row_completion_sound_file))
|
||||
BIN
main_music.mp3
BIN
main_music.mp3
Binary file not shown.
BIN
main_music.ogg
Normal file
BIN
main_music.ogg
Normal file
Binary file not shown.
BIN
piece_set_3.wav
Normal file
BIN
piece_set_3.wav
Normal file
Binary file not shown.
BIN
row_completion.wav
Normal file
BIN
row_completion.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user