pygame-tetris/tetris_pygame_hatch/settings.py
2024-01-19 16:39:03 +08:00

69 lines
1.9 KiB
Python

from math import log
import random
from typing import Any, Generator, Tuple
import pygame as pg
vec = pg.math.Vector2
TETROMINO_COLORS: dict[str, str] # TODO pg.Color
TETROMINOES: dict[str, Tuple[tuple[int, int] | vec, tuple[int, int] | vec,
tuple[int, int] | vec, tuple[int, int] | vec]]
CAPTION: str = 'Tetris Pygame Demo'
FPS: float = 60
FIELD_COLOR: Tuple[int, int, int] = (48, 39, 32)
TILE_SIZE = 20
FIELD_SIZE = FIELD_W, FIELD_H = 20, 30
FIELD_RES = FIELD_W * TILE_SIZE, FIELD_H * TILE_SIZE
FALL_TIMEOUT_GENERATOR: Generator[int, Any,
Any] # millseconds, tetromino fall countdown
MOVE_DIRECTIONS = {'l': vec(-1, 0), 'r': vec(1, 0), 'd': vec(0, 1)}
# https://www.pygame.org/docs/ref/color_list.html
TETROMINO_COLORS = {
'T': 'mediumorchid',
'O': 'khaki1',
'J': 'royalblue3',
'L': 'orange',
'I': 'cyan1',
'S': 'seagreen2',
'Z': 'indianred2',
'.': 'azure4',
}
TETROMINOES = {
'T': ((0, 0), (-1, 0), (1, 0), (0, -1)),
'O': ((0, 0), (0, -1), (-1, 0), (-1, -1)),
'J': ((0, 0), (-1, 0), (0, -1), (0, -2)),
'L': ((0, 0), (-1, 0), (-1, -1), (-1, -2)),
'I': ((0, 0), (0, 1), (0, -1), (0, -2)),
'S': ((0, 0), (-1, 0), (0, -1), (1, -1)),
'Z': ((0, 0), (1, 0), (0, -1), (-1, -1))
}
__bag_count: int = 0
def _7bag_picker() -> Generator[str, Any, None]:
global __bag_count
_7bag = list(TETROMINOES.keys())
random.shuffle(_7bag)
while True:
for tetromino in _7bag:
yield tetromino
random.shuffle(_7bag)
if __bag_count:
__bag_count += 1
def countdown_gen() -> Generator[int, Any, None]:
DEFAULT_COUNTDOWN: float = 1 * 1000 # millseconds
while True:
yield int(DEFAULT_COUNTDOWN - log(__bag_count + 1) * 10)
# define your generator which invoked by Tetris class.
TETROMINO_GENERATOR = _7bag_picker()
FALL_TIMEOUT_GENERATOR = countdown_gen()