import pygame from assets import load_sprite from engine import collection from engine.types import ALL_TYPES from ui.scaling import fit_surface, load_type_icon, make_window, request_quit, to_logical WIN_W, WIN_H = 1040, 720 BG = (24, 30, 24) TEXT = (230, 235, 230) MUTED = (150, 155, 150) HINT = (255, 220, 120) PANEL = (32, 38, 32) BTN = (60, 90, 60) BTN_HOVER = (85, 125, 85) TYPE_NAMES = { "radiant": "Radiant", "nocturnal": "Nocturnal", "ice": "Ice", "garden": "Garden", "wildflower": "Wildflower", } TYPE_COLORS = { "radiant": (245, 200, 90), "nocturnal": (150, 120, 220), "ice": (130, 200, 235), "garden": (120, 200, 120), "wildflower": (235, 130, 170), } class StarterScreen: def __init__(self): pygame.init() self.window, self.scale = make_window(WIN_W, WIN_H) self.screen = pygame.Surface((WIN_W, WIN_H)) pygame.display.set_caption("Plants — Choose your starting pinwheel") self.clock = pygame.time.Clock() self.font = pygame.font.SysFont("segoeui", 30) self.bold = pygame.font.SysFont("segoeui", 20, bold=True) self.small = pygame.font.SysFont("segoeui", 16) self.tiny = pygame.font.SysFont("segoeui", 13) self.type_rects = {} cw, ch, gap = 180, 200, 12 total = len(ALL_TYPES) * cw + (len(ALL_TYPES) - 1) * gap x0 = (WIN_W - total) // 2 y0 = 120 for i, pt in enumerate(ALL_TYPES): x = x0 + i * (cw + gap) self.type_rects[pt] = pygame.Rect(x, y0, cw, ch) self.pinwheel_sprite = self._load("Pinwheel") self.mouse_pos = (0, 0) def _load(self, name): return load_sprite(name, "full") def run(self): chosen = False running = True while running: self.clock.tick(60) self.mouse_pos = to_logical(pygame.mouse.get_pos(), self.scale) for event in pygame.event.get(): if event.type == pygame.QUIT: request_quit() running = False elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: pos = to_logical(event.pos, self.scale) for pt, rect in self.type_rects.items(): if rect.collidepoint(pos): collection.init_starter_pinwheel(pt) chosen = True running = False break self._draw() pygame.transform.smoothscale(self.screen, self.window.get_size(), self.window) pygame.display.flip() return chosen def _draw(self): self.screen.fill(BG) title = self.font.render("Choose your starting pinwheel", True, HINT) self.screen.blit(title, title.get_rect(center=(WIN_W // 2, 52))) sub = self.small.render("You start with a single pinwheel of the chosen type. " "Battle to win packs and grow your garden.", True, MUTED) self.screen.blit(sub, sub.get_rect(center=(WIN_W // 2, 88))) for pt, rect in self.type_rects.items(): hover = rect.collidepoint(self.mouse_pos) pygame.draw.rect(self.screen, BTN_HOVER if hover else PANEL, rect, border_radius=10) pygame.draw.rect(self.screen, (110, 150, 110) if hover else (70, 84, 70), rect, 2, border_radius=10) if self.pinwheel_sprite: ic = fit_surface(self.pinwheel_sprite, 96) self.screen.blit(ic, ic.get_rect(center=(rect.centerx, rect.y + 66))) tcol = TYPE_COLORS.get(pt, TEXT) nm = self.bold.render(TYPE_NAMES.get(pt, pt), True, tcol) self.screen.blit(nm, nm.get_rect(center=(rect.centerx, rect.y + 130))) tic = load_type_icon(pt, 28) if tic: self.screen.blit(tic, tic.get_rect(center=(rect.centerx, rect.y + 160))) hint = self.tiny.render("Click to start", True, MUTED) self.screen.blit(hint, hint.get_rect(center=(rect.centerx, rect.bottom - 14)))