import os import pygame import sys import random pygame.init() vec = pygame.math.Vector2 HEIGHT = 450 WIDTH = 400 ACC = 0.5 FRIC = -0.12 FPS = 60 PLAYER_SIZE = (30, 30) FramePerSec = pygame.time.Clock() displaysurface = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Cat Platformer") # Background loading bg_frames = [] bg_folder = "bg_frames" if os.path.exists(bg_folder): for filename in sorted(os.listdir(bg_folder)): if filename.endswith(('.png', '.jpg', '.gif')): frame = pygame.image.load(os.path.join(bg_folder, filename)).convert() frame = pygame.transform.scale(frame, (WIDTH, HEIGHT)) bg_frames.append(frame) else: print("Missing background frames.") sys.exit() bg_frame_index = 0 bg_frame_delay = 5 bg_timer = 0 # --- Load Skins --- skins_folder = "skins" skin_files = sorted([f for f in os.listdir(skins_folder) if f.endswith(('.png', '.gif'))]) CHARACTER_IMAGES = [pygame.transform.scale(pygame.image.load(os.path.join(skins_folder, f)).convert_alpha(), PLAYER_SIZE) for f in skin_files] # Unlock System unlocked_skins = [0] # only first skin unlocked by default unlocked_levels = [0] # only first level unlocked by default def update_background(): global bg_timer, bg_frame_index bg_timer += 1 if bg_timer >= bg_frame_delay: bg_timer = 0 bg_frame_index = (bg_frame_index + 1) % len(bg_frames) displaysurface.blit(bg_frames[bg_frame_index], (0, 0)) def draw_text(text, font_size, color, center): font = pygame.font.SysFont("Verdana", font_size) surface = font.render(text, True, color) rect = surface.get_rect(center=center) displaysurface.blit(surface, rect) def quest_menu(): while True: update_background() draw_text("Quest Menu", 30, (255, 255, 255), (WIDTH // 2, 40)) draw_text("Score to unlock skins!", 20, (255, 255, 255), (WIDTH // 2, 100)) draw_text("ESC to go back", 20, (255, 255, 255), (WIDTH // 2, 400)) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return def start_screen(): selected = 0 cat_spacing = 60 total_width = cat_spacing * (len(CHARACTER_IMAGES) - 1) start_x = WIDTH // 2 - total_width // 2 play_button = pygame.Rect(WIDTH//2 - 60, 320, 120, 40) quest_button = pygame.Rect(WIDTH//2 - 60, 370, 120, 30) while True: update_background() draw_text("Choose Your Cat!", 25, (255, 255, 255), (WIDTH // 2, 30)) for i in range(len(CHARACTER_IMAGES)): x = start_x + i * cat_spacing y = 100 border_rect = pygame.Rect(x - 5, y - 5, PLAYER_SIZE[0] + 10, PLAYER_SIZE[1] + 10) if i == selected: pygame.draw.rect(displaysurface, (255, 255, 0), border_rect, 3) displaysurface.blit(CHARACTER_IMAGES[i], (x, y)) if i not in unlocked_skins: pygame.draw.line(displaysurface, (255, 0, 0), (x, y), (x + PLAYER_SIZE[0], y + PLAYER_SIZE[1]), 2) pygame.draw.line(displaysurface, (255, 0, 0), (x + PLAYER_SIZE[0], y), (x, y + PLAYER_SIZE[1]), 2) pygame.draw.rect(displaysurface, (50, 200, 50), play_button, border_radius=5) draw_text("PLAY", 20, (255, 255, 255), play_button.center) pygame.draw.rect(displaysurface, (70, 70, 200), quest_button, border_radius=5) draw_text("QUESTS", 18, (255, 255, 255), quest_button.center) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: selected = (selected - 1) % len(CHARACTER_IMAGES) elif event.key == pygame.K_RIGHT: selected = (selected + 1) % len(CHARACTER_IMAGES) elif event.key == pygame.K_RETURN: if selected in unlocked_skins: return selected elif event.type == pygame.MOUSEBUTTONDOWN: if play_button.collidepoint(event.pos) and selected in unlocked_skins: return selected elif quest_button.collidepoint(event.pos): quest_menu() def level_menu(): selected = 0 while True: update_background() draw_text("Select Level", 30, (255, 255, 255), (WIDTH // 2, 50)) for i in range(10): color = (50, 200, 50) if i in unlocked_levels else (100, 100, 100) rect = pygame.Rect(40 + (i % 5) * 65, 120 + (i // 5) * 60, 50, 40) pygame.draw.rect(displaysurface, color, rect, border_radius=5) draw_text(str(i+1), 20, (0, 0, 0), rect.center) if i == selected: pygame.draw.rect(displaysurface, (255, 255, 0), rect, 3, border_radius=5) pygame.display.update() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: selected = (selected - 1) % 10 elif event.key == pygame.K_RIGHT: selected = (selected + 1) % 10 elif event.key == pygame.K_RETURN: if selected in unlocked_levels: return selected # Note: You still need to integrate this into the rest of your game loop logic. # You should call `main_game(level, selected_cat)` and update score tracking to unlock content.