v1.2: Log zeigt gewaehlte Sequenz (nie zweimal dieselbe), Anleitung vor Moduswahl (jede Runde), Roll-Sound-Kanal reserviert (Fix kein Sound), frueheres Abbremsen + Snap-Fenster 160px, 10s Cooldown am Ende, Sprueche nach Prozent (sayings.py), 56 Tests.
This commit is contained in:
1 parent
d970185e75
commit
e3a0c5a57d
11 files changed
+319
-37
No files matched your search
+48
-9
@@ -205,23 +205,62 @@ def draw_dim(surface: pygame.Surface, alpha: int = 170) -> None:
|
||||
surface.blit(overlay, (0, 0))
|
||||
|
||||
|
||||
def _wrap_text(text: str, font: pygame.font.Font, max_width: int) -> list[str]:
|
||||
"""Bricht eine Zeile an Wortgrenzen um, wenn sie zu breit würde."""
|
||||
words = text.split()
|
||||
if not words:
|
||||
return [text]
|
||||
lines: list[str] = []
|
||||
current = words[0]
|
||||
for word in words[1:]:
|
||||
candidate = f"{current} {word}"
|
||||
if font.size(candidate)[0] <= max_width:
|
||||
current = candidate
|
||||
else:
|
||||
lines.append(current)
|
||||
current = word
|
||||
lines.append(current)
|
||||
return lines
|
||||
|
||||
|
||||
def draw_overlay_lines(
|
||||
surface: pygame.Surface,
|
||||
assets,
|
||||
lines: list[str],
|
||||
) -> None:
|
||||
"""Dunkler Schleier mit zentrierten Textzeilen (Ergebnis-Anzeige)."""
|
||||
"""Dunkler Schleier mit zentrierten Textzeilen (Ergebnis-Anzeige).
|
||||
|
||||
Die erste Zeile wird gross gesetzt, alle weiteren klein – so passen auch
|
||||
längere Sprüche auf den Schirm.
|
||||
"""
|
||||
draw_dim(surface, 220)
|
||||
|
||||
center_y = config.SCREEN_HEIGHT // 2
|
||||
line_gap = 16
|
||||
big = assets.font
|
||||
small = assets.font_small or big
|
||||
max_width = config.SCREEN_WIDTH - 200
|
||||
|
||||
rendered: list[pygame.Surface] = []
|
||||
total_height = 0
|
||||
for line in lines:
|
||||
image = assets.font.render(line, True, config.COLOR_WHITE)
|
||||
rendered.append(image)
|
||||
total_height += image.get_height() + line_gap
|
||||
y = center_y - total_height // 2
|
||||
for index, line in enumerate(lines):
|
||||
font = big if index == 0 else small
|
||||
for part in _wrap_text(line, font, max_width):
|
||||
rendered.append(font.render(part, True, config.COLOR_WHITE))
|
||||
|
||||
line_gap = 18
|
||||
total_height = sum(image.get_height() + line_gap for image in rendered)
|
||||
y = config.SCREEN_HEIGHT // 2 - total_height // 2
|
||||
|
||||
# Dunkles Band hinter dem Text, damit er auch über Koffern lesbar bleibt.
|
||||
widest = max(image.get_width() for image in rendered)
|
||||
band = pygame.Surface((widest + 120, total_height + 20), pygame.SRCALPHA)
|
||||
band.fill((0, 0, 0, 170))
|
||||
surface.blit(
|
||||
band,
|
||||
(
|
||||
config.SCREEN_WIDTH // 2 - band.get_width() // 2,
|
||||
y - 10,
|
||||
),
|
||||
)
|
||||
|
||||
for image in rendered:
|
||||
surface.blit(image, (config.SCREEN_WIDTH // 2 - image.get_width() // 2, y))
|
||||
y += image.get_height() + line_gap
|
||||
Reference in new issue
Block a user