Files
Habegger_loader_game/loader_game/difficulty.py
T

39 lines
999 B
Python

"""Schwierigkeitsstufen: wie schnell die Koffer einlaufen.
``hard`` entspricht dem Tempo des Altstands (6 bzw. 2 Pixel pro Frame bei
120 fps = 720 bzw. 240 Pixel pro Sekunde).
"""
from __future__ import annotations
from dataclasses import dataclass
@dataclass(frozen=True, slots=True)
class Difficulty:
"""Eine Stufe. ``speed_fast`` gilt bis kurz vor der Barriere, dann ``speed_slow``."""
key: str
label: str
speed_fast: float
speed_slow: float
def __str__(self) -> str:
return self.label
DIFFICULTIES: tuple[Difficulty, ...] = (
Difficulty("easy", "Easy", speed_fast=420.0, speed_slow=140.0),
Difficulty("normal", "Normal", speed_fast=570.0, speed_slow=190.0),
Difficulty("hard", "Hard", speed_fast=720.0, speed_slow=240.0),
)
DEFAULT_DIFFICULTY: Difficulty = DIFFICULTIES[1]
def by_key(key: str) -> Difficulty:
for difficulty in DIFFICULTIES:
if difficulty.key == key:
return difficulty
return DEFAULT_DIFFICULTY