import pygame
import math
import os

def create_glow(surface, color, radius):
    """Crée un effet de lueur (glow) autour d'une forme."""
    glow = pygame.Surface((radius * 2, radius * 2), pygame.SRCALPHA)
    pygame.draw.circle(glow, (*color, 50), (radius, radius), radius)
    pygame.draw.circle(glow, (*color, 100), (radius, radius), radius * 0.8)
    pygame.draw.circle(glow, (*color, 150), (radius, radius), radius * 0.6)
    surface.blit(glow, (surface.get_width()//2 - radius, surface.get_height()//2 - radius))

def generate_player_image():
    surf = pygame.Surface((64, 64), pygame.SRCALPHA)
    # Lueur bleue
    create_glow(surf, (0, 255, 255), 32)
    # Triangle central pointant vers la droite (0 degrés)
    points = [(52, 32), (16, 16), (16, 48)]
    pygame.draw.polygon(surf, (255, 255, 255), points)
    pygame.draw.polygon(surf, (0, 255, 255), points, 3)
    
    # Réacteur
    pygame.draw.circle(surf, (255, 100, 0), (12, 32), 6)
    
    pygame.image.save(surf, "player.png")

def generate_bullet_image():
    surf = pygame.Surface((16, 16), pygame.SRCALPHA)
    create_glow(surf, (57, 255, 20), 8)
    pygame.draw.circle(surf, (255, 255, 255), (8, 8), 4)
    pygame.image.save(surf, "bullet.png")

def generate_enemy_basic_image():
    surf = pygame.Surface((48, 48), pygame.SRCALPHA)
    create_glow(surf, (255, 20, 147), 24)
    # Carré losange
    points = [(24, 8), (40, 24), (24, 40), (8, 24)]
    pygame.draw.polygon(surf, (255, 20, 147), points)
    pygame.draw.polygon(surf, (255, 255, 255), points, 2)
    pygame.image.save(surf, "enemy_basic.png")

def generate_enemy_fast_image():
    surf = pygame.Surface((40, 40), pygame.SRCALPHA)
    create_glow(surf, (255, 255, 0), 20)
    # Triangle pointu
    points = [(20, 4), (36, 36), (20, 28), (4, 36)]
    pygame.draw.polygon(surf, (255, 255, 0), points)
    pygame.draw.polygon(surf, (255, 255, 255), points, 2)
    pygame.image.save(surf, "enemy_fast.png")

def generate_enemy_tank_image():
    surf = pygame.Surface((64, 64), pygame.SRCALPHA)
    create_glow(surf, (255, 165, 0), 32)
    # Hexagone
    import math
    points = []
    for i in range(6):
        angle = math.radians(60 * i)
        x = 32 + 20 * math.cos(angle)
        y = 32 + 20 * math.sin(angle)
        points.append((x, y))
    pygame.draw.polygon(surf, (255, 165, 0), points)
    pygame.draw.polygon(surf, (255, 255, 255), points, 3)
    # Oeil central
    pygame.draw.circle(surf, (255, 0, 0), (32, 32), 8)
    pygame.image.save(surf, "enemy_tank.png")

def generate_xp_orb_small():
    surf = pygame.Surface((16, 16), pygame.SRCALPHA)
    create_glow(surf, (0, 191, 255), 8) # Deep Sky Blue glow
    points = [(8, 4), (12, 8), (8, 12), (4, 8)]
    pygame.draw.polygon(surf, (135, 206, 250), points)
    pygame.draw.polygon(surf, (255, 255, 255), points, 1)
    pygame.image.save(surf, "xp_orb_small.png")

def generate_xp_orb_med():
    surf = pygame.Surface((24, 24), pygame.SRCALPHA)
    create_glow(surf, (50, 205, 50), 12) # Lime Green glow
    points = [(12, 6), (18, 12), (12, 18), (6, 12)]
    pygame.draw.polygon(surf, (144, 238, 144), points)
    pygame.draw.polygon(surf, (255, 255, 255), points, 1)
    pygame.image.save(surf, "xp_orb_med.png")

def generate_xp_orb_large():
    surf = pygame.Surface((32, 32), pygame.SRCALPHA)
    create_glow(surf, (255, 215, 0), 16) # Gold / Yellow glow
    points = [(16, 6), (24, 16), (16, 26), (8, 16)]
    pygame.draw.polygon(surf, (255, 255, 0), points)
    pygame.draw.polygon(surf, (255, 255, 255), points, 2)
    pygame.image.save(surf, "xp_orb_large.png")

if __name__ == "__main__":
    pygame.init()
    # On a besoin d'un display valide pour certaines opérations de surface même sans l'afficher
    pygame.display.set_mode((100, 100), pygame.HIDDEN)
    
    os.chdir("c:\\Users\\leopo\\Desktop\\site_internet\\neon_nebula_survivor\\assets")
    print("Génération des textures...")
    generate_player_image()
    generate_bullet_image()
    generate_enemy_basic_image()
    generate_enemy_fast_image()
    generate_enemy_tank_image()
    generate_xp_orb_small()
    generate_xp_orb_med()
    generate_xp_orb_large()
    print("Textures générées avec succès dans le dossier assets !")
    pygame.quit()
