feat: improve game music
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import sys
|
||||
import pygame
|
||||
from pygame import mixer
|
||||
from types import FunctionType
|
||||
from tetri5.util import ConfigurationManager
|
||||
from tetri5.util import TextGenerator
|
||||
from tetri5.util import Controller
|
||||
from tetri5.util import SoundManager
|
||||
from tetri5.entity import Well
|
||||
from tetri5.entity import Stack
|
||||
from tetri5.entity import PieceGenerator
|
||||
@@ -39,7 +39,6 @@ class TitleScene(Scene):
|
||||
self._option_one_position = ConfigurationManager.get("position", "option-one")
|
||||
self._option_two_position = ConfigurationManager.get("position", "option-two")
|
||||
self._is_multiplayer = False
|
||||
|
||||
self._change_scence = change_scene
|
||||
|
||||
def draw(self, surface: pygame.Surface) -> None:
|
||||
@@ -53,12 +52,18 @@ class TitleScene(Scene):
|
||||
pygame.draw.circle(surface, self._cursor_color, self._cursor_position, self._tile_size // 3)
|
||||
|
||||
def update(self, elapsed_time: int) -> None:
|
||||
if Controller.key_pressed(pygame.K_UP):
|
||||
option_change = False
|
||||
if Controller.key_pressed(pygame.K_UP) and self._is_multiplayer:
|
||||
self._cursor_position = self._cursor_position_one
|
||||
self._is_multiplayer = False
|
||||
if Controller.key_pressed(pygame.K_DOWN):
|
||||
option_change = True
|
||||
if Controller.key_pressed(pygame.K_DOWN) and not self._is_multiplayer:
|
||||
self._cursor_position = self._cursor_position_two
|
||||
self._is_multiplayer = True
|
||||
option_change = True
|
||||
|
||||
if option_change:
|
||||
SoundManager.play_option_change_sfx() # TODO add cool down
|
||||
|
||||
self._cursor_blink_time += elapsed_time
|
||||
if self._cursor_blink_time >= self._cursor_blink_interval:
|
||||
@@ -66,7 +71,7 @@ class TitleScene(Scene):
|
||||
self._cursor_off = not self._cursor_off
|
||||
|
||||
if Controller.key_pressed(pygame.K_RETURN):
|
||||
self._change_scence(SinglePlayerScene(self._change_scence))
|
||||
self._change_scence(SinglePlayerScene(self._change_scence)) # TODO implement multiplayer
|
||||
|
||||
"""
|
||||
TODO
|
||||
@@ -77,17 +82,14 @@ class SinglePlayerScene(Scene):
|
||||
self._tile_size = ConfigurationManager.get("engine", "tile-size")
|
||||
self._background_color = pygame.Color(ConfigurationManager.get("color", "window-bg"))
|
||||
self._score = 0
|
||||
self._level = 0
|
||||
self._previous_level = 0
|
||||
self._well = Well((280, 80), ConfigurationManager.get("color", "well-1"), ConfigurationManager.get("color", "well-border-1")) # TODO calculate position later and redo color config for well
|
||||
self._stack = Stack(ConfigurationManager.get("color", "stack-1"), ConfigurationManager.get("color", "stack-border-1"))
|
||||
self._current_piece = None
|
||||
self._next_piece = PieceGenerator.get_piece((620, 160))
|
||||
self._main_music = mixer.Channel(0)
|
||||
self._main_music.set_volume(0.7) # TODO add volume to the config
|
||||
self._main_music.play(mixer.Sound(ConfigurationManager.get("sound", "main-music")), -1)
|
||||
self._points_table = ConfigurationManager.get("engine", "points-table")
|
||||
|
||||
self._change_scence = change_scene
|
||||
SoundManager.play_theme_music()
|
||||
|
||||
def draw(self, surface: pygame.Surface) -> None:
|
||||
surface.fill(self._background_color)
|
||||
@@ -132,6 +134,10 @@ class SinglePlayerScene(Scene):
|
||||
self._stack.update(elapsed_time)
|
||||
|
||||
self._score += self._points_table[self._stack.lines_completed_last] * (self._get_level() + 1)
|
||||
|
||||
if self._previous_level != self._get_level():
|
||||
self._previous_level = self._get_level()
|
||||
SoundManager.play_level_up_sfx()
|
||||
|
||||
def _get_level(self) -> int:
|
||||
lines_per_level = ConfigurationManager.get("engine", "lines-per-level")
|
||||
|
||||
Reference in New Issue
Block a user