from player import Player
from sprite_objects import *
from ray_casting import ray_casting_walls
from drawing import Drawing
from interaction import Interaction
import time
from random import randrange

pygame.init()
sc = pygame.display.set_mode((WIDTH, HEIGHT))
sc_map = pygame.Surface(MINIMAP_RES)

sprites = Sprites()
clock = pygame.time.Clock()
player = Player(sprites)
drawing = Drawing(sc, sc_map, player, clock)
interaction = Interaction(player, sprites, drawing)


drawing.menu()
pygame.mouse.set_visible(False)
starttime = time.time()
#interaction.play_music()

while True:
    player.movement()
    drawing.background(player.angle)
    walls, wall_shot = ray_casting_walls(player, drawing.textures)
    drawing.world(walls + [obj.object_locate(player) for obj in sprites.list_of_objects])
    drawing.fps(clock)
    drawing.mini_map(player)
    drawing.player_weapon([wall_shot, sprites.sprite_shot])
    drawing.draw_player_health()

    interaction.interaction_objects()
    interaction.npc_action()
    endtime = time.time()
    if endtime-starttime > 2:
        if randrange(1, 100) < 20:
            interaction.attack()
    interaction.clear_world()
    interaction.check_win()
    interaction.check_lose()

    pygame.display.flip()
    clock.tick()