import pygame
import Element
from datetime import datetime

SCREEN_WIDHT = 800
SCREEN_HEIGHT = 606

background_image = pygame.image.load("images/background.png")
base_character = pygame.image.load("images/base.png")

#elementy stroju
head = Element.Head()
body = Element.BodyElement()
eye = Element.EyeElement()
weapon = Element.WeaponElement()


pygame.init()
screen = pygame.display.set_mode([SCREEN_WIDHT,SCREEN_HEIGHT])
clock = pygame.time.Clock()
pygame.font.init()
my_font = pygame.font.SysFont("Comic Sans MS", 30)

def print_text(screen, text, position):
    caption = my_font.render(text, False, (255,255,255))
    screen.blit(caption,position)


is_game_working = True
is_save = False
while is_game_working:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                gra_działa = False 
            if event.key == pygame.K_q:
                head.nextChoice()
            if event.key == pygame.K_w:
                body.nextChoice()
            if event.key == pygame.K_e:
                weapon.nextChoice()
            if event.key == pygame.K_r:
                eye.nextChoice()
            if event.key == pygame.K_z:
                is_save = True
        elif event.type == pygame.QUIT:
            is_game_working = False
            
     #rysowanie tła       
    screen.blit(background_image, (0,0))
    #rysowanie postaci
    screen.blit(base_character, (270,130))
    #rysowanie elementow postaci
    screen.blit(head.getChosenImage(),(270,130))
    screen.blit(body.getChosenImage(),(270,130))
    screen.blit(weapon.getChosenImage(),(270,130))
    screen.blit(eye.getChosenImage(),(270,130))


    if is_save:
        now = datetime.now()
        current_datetime = now.strftime("%Y-%m-%d-%H-%M-%S")
        pygame.image.save(screen,f"screen/postac{current_datetime}.png")
        is_save = False


    print_text(screen,f"[Q] Głowa {head.choice+1}", (100,100))
    print_text(screen,f"[R] Oczy {eye.choice+1}", (100,140))
    print_text(screen,f"[W] Ubranie {body.choice+1}", (100,180))
    print_text(screen,f"[E] Broń {weapon.choice+1}", (100,220))
    print_text(screen,f"[Z] Zaisz", (100,260))

    #wyczyszczenie ekranu
    pygame.display.flip()
    #ustalanie stałego fps na 30
    clock.tick(30)


pygame.quit()