import pygame
from head import Head
from eye import Eye
from body import Body
from weapon import Weapon

def print_text(screen, text, position, font_size=30, bold=False):
    my_font = pygame.font.SysFont('Comic Sans', font_size,  bold=bold)
    my_text = my_font.render(text, False, (255, 255, 255))
    screen.blit(my_text, position)
    pass

def save_img(screen, filename):
    pygame.image.save(screen, filename)
    pass

pygame.init()

SCREEN_WIDTH = 800
SCREEN_HIGHT = 600

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HIGHT))
background = pygame.image.load('images/background.png')
character = pygame.image.load('images/base.png')

pygame.display.set_caption('Kreator postaci')

# TWORZĘ ELEMENTY DLA BOHATERA
head = Head()
eye = Eye()
body = Body()
weapon = Weapon()

running = True
should_save = False
img_no = 1

while running:

    for event in pygame.event.get():

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_UP:
                head.get_next()
            if event.key == pygame.K_DOWN:
                eye.get_next()
            if event.key == pygame.K_LEFT:
                body.get_next()
            if event.key == pygame.K_RIGHT:
                weapon.get_next()
            if event.key == pygame.K_s:
                should_save = True
            if event.key == pygame.K_ESCAPE:
                running = False

        if event.type == pygame.QUIT:
            running = False
        pass

    screen.blit(background, (0, 0))
    screen.blit(character, (270, 130))
    screen.blit(head.show_element(), (270, 130))
    screen.blit(eye.show_element(), (270, 130))
    screen.blit(body.show_element(), (270, 130))
    screen.blit(weapon.show_element(), (270, 130))

    if should_save:
        save_img(screen, f'obrazek_{img_no}.png')
        should_save = False
        img_no += 1
        pass

    #WYŚWIETLENIE INFORMACJI O WYBRANYM ELEMENCIE
    print_text(screen, f'Sterowanie:', (10, 5), bold=True)
    print_text(screen, f'[UP] Głowa {head.choice}', (10, 50), font_size=20)
    print_text(screen, f'[DOWN] Oczy {eye.choice}', (10, 80), font_size=20)
    print_text(screen, f'[LEFT] Strój {body.choice}', (10, 110), font_size=20)
    print_text(screen, f'[RIGHT] Broń {weapon.choice}', (10, 140), font_size=20)
    print_text(screen, f'[s] Zapisz', (10, 170), font_size=20)
    print_text(screen, f'[ESC] Wyjdź', (10, 200), font_size=20)

    pygame.display.flip()

quit()