# def oblicz_wysokosc(szerokosc, wysokosc, p_szerokosc): 
#     # def oblicz 
#     wys = int(szerokosc, wysokosc, p_szerokosc)
#     return wys

# test = oblicz_wysokosc(16,9,1920)
# print(test)

#--------------------------------------------# 𝐙𝐀𝐃𝐀𝐍𝐈𝐄 𝟏 #-----------------------------------------------------------#
#-----------#"C:/Users/13-19 lat/AppData/Local/Programs/Python/Python39/python.exe" -m pip install pygame #-----------#

import pygame #- Importujemy moduł -#
from random import choice, randint
pygame.init() #- Włączenie pygame -#

#- Create a window width and height -#

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

screen_surface = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

#- Name for my window -#
pygame.display.set_caption("Da First Game")

#- FPS Counter (60FPS) -#
clock = pygame.time.Clock()
FPS = 60
fps_cnt = 0

#- Keeps game on till closed -#
game_status = True

bonus_images = [
    "bonus_1.png",
    "bonus_2.png",
    "bonus_3.png"
]

bonus_object = [] #- Photos that will appear randomly -#

def generate_bonus_object():
    image_name = choice(bonus_images)
    #- Picks random image -#
    x = randint(0, SCREEN_WIDTH)
    y = randint(0, SCREEN_HEIGHT)
    position = [x, y]

    new_obj = load_image(image_name, position)
    bonus_object.append(new_obj)

def print_bonus_objects():
    for obj in bonus_object:
        print_image(obj)
        pass
    pass


def load_image(img_path: str, position):
    image = pygame.image.load(img_path) #- Loads image from the argument function-#
    surface = image.convert() #- Conferts the image to Surface-#
    transparent_color = (0, 0, 0)
    surface.set_colorkey(transparent_color) #- Set color to 0,0,0 -#

    rect = surface.get_rect(center = position)
    return [image,surface, rect]

player_pos = [SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2] #- Middle of screen -#
player = load_image('player.png', player_pos)

def print_image(img_list) -> None:
    image, surface, rect = img_list #- Copies 3 texts -#
    screen_surface.blit(surface, rect)
    pass

#- Function to change players position -#
def set_position_image(img_list, position):
    image, surface, rect = img_list
    rect = surface.get_rect(center = position)
    return [image, surface, rect]

def calculate_player_movement(keys):
    speed = 10
    delta_x = 0
    delta_y = 0
    
    if keys[pygame.K_LSHIFT]:
        speed *= 2
        pass
    if keys[pygame.K_w]: #- If 'W' pressed on the keyboard -#
        delta_y -= speed
        pass
    if keys[pygame.K_s]: #- If 'S' pressed on the keyboard -#
        delta_y += speed
        pass
    if keys[pygame.K_a]: #- If 'A' pressed on the keyboard -#
        delta_x -= speed
        pass
    if keys[pygame.K_d]: #- If 'D' pressed on the keyboard -#
        delta_x += speed
        pass

    return [delta_x, delta_y]


def limit_position(position):
    x, y = position
    x = max(0, min(x, SCREEN_WIDTH))
    y = max(0, min(y, SCREEN_HEIGHT))
    return[x, y]

#- Code will be functioned when game is on -#
while game_status:
    #- Computer reads the current event -#
    events = pygame.event.get()

    for event in events:
        # print(event)
        if event.type == pygame.QUIT:
            game_status = False #- Put Game_Status to False-#
            pass
        pass

    pressed_keys = pygame.key.get_pressed()

    delta_x, delta_y = calculate_player_movement(pressed_keys)

    player_pos[0] += delta_x
    player_pos[1] += delta_y
    player = set_position_image(player, player_pos)
    
    player_pos = limit_position(player_pos)
    
    screen_surface.fill((25, 125, 12))

    if fps_cnt % (FPS * 1) == 0:
        generate_bonus_object()
        pass
    print_bonus_objects()

    print_image(player)
    pygame.display.update() #- Reload the current action -#
    fps_cnt += 1
    clock.tick(FPS)
    pass

pygame.quit() #- Closing game -#
quit() #- Stopping the scripts -#