import pygame, sys
from pygame.locals import *
import random
import math 
 
# pygame.init()

pygame.display.init()
pygame.font.init()

w = pygame.display.Info().current_w
h = pygame.display.Info().current_h
screen_scale_factor_w = w / 1920
screen_scale_factor_h = h / 1080

# screen_scale_factor = screen_scale_factor_w

MOUSE_BUTTON_RIGHT = 3

SCREEN_WIDTH = 400 
FPS = 60
FramePerSec = pygame.time.Clock()
game_level = 1
enemy_list = []
 
BLUE  = (0, 0, 255)
RED   = (255, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

TEXT_COLOR = (0, 0, 0)


money = 15000

def screen_scale_h(h_px, scale_factor):
    return int(h_px * scale_factor)


def screen_scale_w(w_px, scale_factor):
    return int(w_px * scale_factor)

MENU_PADDING = screen_scale_w(10, screen_scale_factor_w)
HEART_POS_X = screen_scale_w(1700, screen_scale_factor_w)
HEART_POS_Y = screen_scale_h(700, screen_scale_factor_h)

DISPLAYSURF = pygame.display.set_mode((screen_scale_w(1920, screen_scale_factor_w), screen_scale_h(1080, screen_scale_factor_h)), pygame.FULLSCREEN)
DISPLAYSURF.fill(WHITE)
pygame.display.set_caption("Game")

pygame.font.init()
my_font = pygame.font.SysFont("Arial", screen_scale_w(30, screen_scale_factor_w) , bold=True, italic=False)
you_died_font = pygame.font.SysFont("Arial", screen_scale_w(300, screen_scale_factor_w), bold=True, italic=False)


exit_text_surface = my_font.render("Exit", False, TEXT_COLOR)
exit_text_x = screen_scale_w(1800, screen_scale_factor_w)
exit_text_y = screen_scale_h(16, screen_scale_factor_h)
exit_rect = exit_text_surface.get_rect(topleft=(exit_text_x, exit_text_y))

you_died = you_died_font.render('YOU DIED', False, (255, 0, 0))

text_surface = my_font.render("money: " + str(money), False, TEXT_COLOR)
text_surface_x = screen_scale_w(16, screen_scale_factor_w)
text_surface_y = screen_scale_h(16, screen_scale_factor_h)

level_text_surface = my_font.render("Level: " + str(game_level), False, TEXT_COLOR)
level_text_surface_x = screen_scale_w(16, screen_scale_factor_w)
level_text_surface_y = screen_scale_h(48, screen_scale_factor_h)

snowman_list = []
cakeman_list = []
snowball_list = []
reindeer_list = []
laser_beam_list = []

class CakeMan(pygame.sprite.Sprite):
    def __init__ (self, x, y):
        super().__init__()
        self.image = pygame.image.load("kagemand/kagemand1.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h)))
        self.rect.center = (x, y)
        self.animation_step = 0

    def draw(self, surface):
        surface.blit(self.image, self.rect)

class Reindeer(pygame.sprite.Sprite):
    def __init__ (self, x, y):
        super().__init__()
        self.image = pygame.image.load("reindeer/r1.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h) ))
        self.rect.center = (x, y)
        self.speed = 180
        self.shoot_laser_beam = self.speed
        self.animation_step = 0

    def draw(self, surface):
        surface.blit(self.image, self.rect)
        self.shoot_laser_beam = self.shoot_laser_beam - 1
        if self.shoot_laser_beam == -1:
            return
        elif self.shoot_laser_beam == 0:
            # Throw snowball. 
            # print("Laser beam: x: " + str(self.rect.center[0]) + "y:" + str(self.rect.center[1]))
            laser_beam_list.append(Laser_Beam(self.rect.center[0], self.rect.center[1]))
            # rest sownball counter 
            self.shoot_laser_beam = self.speed

class Snowman(pygame.sprite.Sprite):
    def __init__(self, x, y):
        super().__init__() 
        self.image = pygame.image.load("snowmand.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h)))
        self.rect.center = (x, y)
        self.speed = 180
        self.throw_snowball_counter = self.speed

    def draw(self, surface, enemy_list):
        surface.blit(self.image, self.rect)
        self.throw_snowball_counter = self.throw_snowball_counter - 1
        if self.throw_snowball_counter == -1:
            return
        elif self.throw_snowball_counter == 0:
            # Throw snowball. 
            
            #Check if enemy is in reachable distance
            inside_circle = 0
            for enemy in enemy_list:

                d = math.sqrt((xp - self.rect.center.x)**2 + (yp - self.rect.center.y)**2)
                inside_circle = 
                if enemy.alive == 1:
                    inside_circle = 1

                if (inside_circle):

                    # print("Snowball: x: " + str(self.rect.center[0]) + "y:" + str(self.rect.center[1]))
                    snowball_list.append(Snowball(enemy, self.rect.center[0], self.rect.center[1]))
        
                    # rest sownball counter 
                    self.throw_snowball_counter = self.speed
                    return


class Enemy(pygame.sprite.Sprite):
      def __init__(self, x, y, heart, health):
        super().__init__()
        self.image = pygame.image.load("elf.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.center = (x, y)

        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h) ))
        
        self.health_bar_color = GREEN
        self.health_bar_width = 0
        self.path = 0
        self.max_health = health
        self.health = self.max_health
        self.alive = 1
        self.heart = heart
        self.speed = screen_scale_w(2, screen_scale_factor_w)
        self.calculate_life_bar()
 
      def damage(self, amount):
        self.health = self.health - amount
        if(self.health <= 0):
            self.alive = 0
            add_money(1000)
            return

        self.calculate_life_bar()


      def calculate_life_bar(self):
        #Beregn størrelsen på liv baren:
        life_ratio = self.health / self.max_health
        
        if life_ratio >= 0.75:
            self.health_bar_color = GREEN
        elif life_ratio < 0.75 and life_ratio > 0.26:
            self.health_bar_color = YELLOW
        else:
            self.health_bar_color = RED

        self.health_bar_width = self.rect.w * (self.health / self.max_health)



      def move(self, player):
        if (self.path == 0):
            if (self.rect.right < screen_scale_w(300, screen_scale_factor_w)):
                self.rect.move_ip(self.speed,0)
            else:
                self.path = 1
        if (self.path == 1):
            if(self.rect.bottom < screen_scale_h(890, screen_scale_factor_h)):
                self.rect.move_ip(0,self.speed)
            else:
                self.path = 2
        if(self.path == 2):
            if(self.rect.right < screen_scale_w(1128, screen_scale_factor_w)):
                self.rect.move_ip(self.speed,0)
            else:
                self.path = 3
        if (self.path == 3):
            if(self.rect.top > screen_scale_h(516, screen_scale_factor_h)):
                self.rect.move_ip(0,-self.speed)
            else:
                self.path = 4
        if (self.path == 4):
            if(self.rect.left > screen_scale_w(847, screen_scale_factor_w)):
                self.rect.move_ip(-self.speed,0)
            else:
                self.path = 5
        if (self.path == 5):
            if(self.rect.top > screen_scale_h(246, screen_scale_factor_h)):
                self.rect.move_ip(0,-self.speed)
            else:
                self.path = 6
        if (self.path == 6):
            if (self.rect.right < screen_scale_w(1248, screen_scale_factor_w)):
                self.rect.move_ip(self.speed,0)
            else:
                self.path = 7
        if (self.path == 7):
            if (self.rect.bottom < screen_scale_h(570, screen_scale_factor_h)):
                self.rect.move_ip(0,self.speed)
            else:
                self.path = 8
        if (self.path == 8):
            if (self.rect.right < screen_scale_w(1548, screen_scale_factor_w)):
                self.rect.move_ip(self.speed,0)
            else:
                self.path = 'end'
        if (self.path == 'end'):
            self.alive = 0
            self.heart.lives -= 20

      def draw(self, surface):
        surface.blit(self.image, self.rect) 
        pygame.draw.rect(DISPLAYSURF,self.health_bar_color,(self.rect.x, (self.rect.y + self.rect.h + 8), screen_scale_w(self.health_bar_width, screen_scale_factor_w) , screen_scale_w(5, screen_scale_factor_h) ))

class Snowball(pygame.sprite.Sprite):
      def __init__(self, enemy, x, y):
        super().__init__() 
        self.image = pygame.image.load("snowball.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.center=(x, y) 
        self.enemy = enemy
 
      def move(self, snowball_list, enemy_list):


        if not self.enemy.alive:
            snowball_list.remove(self)
            return

        enemy_x    = self.enemy.rect.x
        enemy_y    = self.enemy.rect.y

        snowball_x = self.rect.x
        snowball_y = self.rect.y

        if abs(enemy_x - snowball_x) < 8 and abs(enemy_y - snowball_y) < 8:
            snowball_list.remove(self)
            self.enemy.damage(25)



        delta_move_x = 0
        delta_move_y = 0


        if enemy_x < snowball_x:
            delta_move_x = -4
        elif enemy_x > snowball_x:
            delta_move_x = 4


        if enemy_y < snowball_y:
            delta_move_y = -4
        elif enemy_y > snowball_y:
            delta_move_y = 4


        self.rect.move_ip(delta_move_x, delta_move_y)
        
        #if (self.rect.right > 600):
        #    self.rect.top = 0
        #    self.rect.center = (0, 400)

        #if self.rect.colliderect(player.rect):
        #    print("HIT")

      def draw(self, surface):
        surface.blit(self.image, self.rect)  

class Laser_Beam(pygame.sprite.Sprite):
      def __init__(self, x, y):
        super().__init__() 
        self.image = pygame.image.load("reindeer/laser_beam.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.center=(x, y) 
 
      def move(self, player):
        self.rect.move_ip(4,0)
        #if (self.rect.right > 600):
        #    self.rect.top = 0
        #    self.rect.center = (0, 400)

        # if self.rect.colliderect(player.rect):
        #         print("HIT")

      def draw(self, surface):
        surface.blit(self.image, self.rect)  

 
class MenuSnowman(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__() 
        self.image = pygame.image.load("snowmand.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.center = (screen_scale_w(580, screen_scale_factor_w), screen_scale_h(80, screen_scale_factor_h))
        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h)) )
        self.price = 2500
        self.text = my_font.render(str(self.price) , False, TEXT_COLOR)
        self.selected = 0

    def draw(self, surface):
        if self.selected == 1:
            pygame.draw.rect(DISPLAYSURF,BLUE,(menu_snowman.rect.x - MENU_PADDING , menu_snowman.rect.y - MENU_PADDING, screen_scale_w((menu_snowman.rect.w + 2 * MENU_PADDING), screen_scale_factor_w) , screen_scale_h((menu_snowman.rect.h + 2 * MENU_PADDING), screen_scale_factor_h )))
        surface.blit(self.image, self.rect)
        surface.blit(self.text,(self.rect.x, self.rect.y + (screen_scale_h(100, screen_scale_factor_h))))
    
    def get_pos(self):
        return self.rect.pos

class MenuCakeman(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__() 
        self.image = pygame.image.load("kagemand/kagemand1.png").convert_alpha()
        self.rect = self.image.get_rect()
        #self.rect.scale_by(screen_scale_factor) 
        self.rect.center = (screen_scale_w(720, screen_scale_factor_w), screen_scale_h(80, screen_scale_factor_h))
        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h)) )
        self.price = 5000
        self.text = my_font.render(str(self.price) , False, TEXT_COLOR)
        self.selected = 0

    def draw(self, surface):
        if self.selected == 1:
            pygame.draw.rect(DISPLAYSURF,BLUE,(menu_cakeman.rect.x - MENU_PADDING, menu_cakeman.rect.y - MENU_PADDING, screen_scale_w((menu_cakeman.rect.w + 2 * MENU_PADDING), screen_scale_factor_w), screen_scale_h((menu_cakeman.rect.h + 2 * MENU_PADDING), screen_scale_factor_h) ))
        surface.blit(self.image, self.rect)
        surface.blit(self.text,(self.rect.x ,self.rect.y + (screen_scale_h(100, screen_scale_factor_h)) ))
    
    def get_pos(self):
        return self.rect.pos

class MenuReindeer(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__() 
        self.image = pygame.image.load("reindeer/r1.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.center = (screen_scale_w(850, screen_scale_factor_w), screen_scale_h(80, screen_scale_factor_h))
        self.image = pygame.transform.smoothscale(self.image, (screen_scale_w(self.rect.w, screen_scale_factor_w), screen_scale_h(self.rect.h, screen_scale_factor_h)) )
        self.price = 7500
        self.text = my_font.render(str(self.price) , False, TEXT_COLOR)
        self.selected = 0

    def draw(self, surface):
        if self.selected == 1:
            pygame.draw.rect(DISPLAYSURF,BLUE,(self.rect.x - MENU_PADDING , self.rect.y - MENU_PADDING, screen_scale_w((self.rect.w + 2 * MENU_PADDING), screen_scale_factor_w) , screen_scale_h((self.rect.h + 2 * MENU_PADDING), screen_scale_factor_h )))
        surface.blit(self.image, self.rect)
        surface.blit(self.text,(self.rect.x + (screen_scale_w(20, screen_scale_factor_w)), self.rect.y + (screen_scale_h(100, screen_scale_factor_h))))
    
    def get_pos(self):
        return self.rect.pos


scaleFactor = 2 * screen_scale_factor_w
class Heart(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image0 = pygame.image.load('0_hjerte.png').convert_alpha()

        self.image20 = pygame.image.load('20_hjerte.png').convert_alpha()
        self.image20 = pygame.transform.scale(self.image20, (screen_scale_w(74, scaleFactor), screen_scale_h(79, scaleFactor)))

        self.image40 = pygame.image.load('40_hjerte.png').convert_alpha()
        self.image40 = pygame.transform.scale(self.image40, (screen_scale_w(74, scaleFactor), screen_scale_h(79, scaleFactor)))

        self.image60 = pygame.image.load('60_hjerte.png').convert_alpha()
        self.image60 = pygame.transform.scale(self.image60, (screen_scale_w(74, scaleFactor), screen_scale_h(79, scaleFactor)))

        self.image80 = pygame.image.load('80_hjerte.png').convert_alpha()
        self.image80 = pygame.transform.scale(self.image80, (screen_scale_w(74, scaleFactor), screen_scale_h(79, scaleFactor)))

        self.image100 = pygame.image.load('100_hjerte.png').convert_alpha()
        self.image100 = pygame.transform.scale(self.image100, (screen_scale_w(74, scaleFactor), screen_scale_h(79, scaleFactor)))

        self.lives = 100

    def draw(self, surface):
        if self.lives == 100:
            surface.blit(self.image100, (HEART_POS_X, HEART_POS_Y))
        elif self.lives == 80:
            surface.blit(self.image80, (HEART_POS_X, HEART_POS_Y))
        elif self.lives == 60:
            surface.blit(self.image60, (HEART_POS_X, HEART_POS_Y))
        elif self.lives == 40:
            surface.blit(self.image40, (HEART_POS_X, HEART_POS_Y))
        elif self.lives == 20:
            surface.blit(self.image20, (HEART_POS_X, HEART_POS_Y))
        elif self.lives == 0:
            surface.blit(self.image0, (HEART_POS_X, HEART_POS_Y))


def try_to_buy(new_tower, price):
    global money
    global text_surface
    
    if not valid_space(new_tower):
        return False
    
    if money >= price:
        money = money - price
        text_surface = my_font.render("money: " + str(money), False, TEXT_COLOR)
        
        return True

    return False

def add_money(price):
    global money
    global text_surface
    money = money + price
    text_surface = my_font.render("money: " + str(money), False, TEXT_COLOR)


def check_round_end():
    global enemy_list
    global snowball_list

    for i in range(len(enemy_list)):
        if (enemy_list[i].alive == 1):
            return False
    
    snowball_list = []

    print("Level ended")
    return True


def level_up():
    global game_level
    global level_text_surface
    game_level = game_level + 1
    level_text_surface = my_font.render("Level: " + str(game_level), False, TEXT_COLOR)

    start_new_level(10, game_level * 100)


heart = Heart()

def start_new_level(count, health):
    global screen_scale_factor_w
    global screen_scale_factor_h
    global enemy_list
    global heart
    enemy_list = []
    enemy_pos_x = screen_scale_w(60, screen_scale_factor_w)
    enemy_pos_y = screen_scale_h(350, screen_scale_factor_h)
    for i in range(count):
        enemy_list.append(Enemy(-enemy_pos_x * i, enemy_pos_y, heart, health))


def valid_space(new_tower):
    global snowman_list
    global cakeman_list
    global reindeer_list

    combined_tower_list = snowman_list + cakeman_list + reindeer_list
    for old_tower in combined_tower_list:
        if new_tower.rect.colliderect(old_tower.rect):
            return False

    return True




menu_snowman  = MenuSnowman()
menu_cakeman  = MenuCakeman()
menu_reindeer = MenuReindeer()
# cakeman = CakeMan(300, 400)



enemy_pos_x = screen_scale_w(60, screen_scale_factor_w)
enemy_pos_y = screen_scale_h(350, screen_scale_factor_h)

start_new_level(5, 100)


kagemand_animation_step = 0
kagemand_animation = []
kagemand_animation_temp = [
    pygame.image.load("kagemand/kagemand1.png").convert_alpha(), 
    pygame.image.load("kagemand/kagemand2.png").convert_alpha(), 
    pygame.image.load("kagemand/kagemand3.png").convert_alpha(), 
    pygame.image.load("kagemand/kagemand4.png").convert_alpha(), 
    pygame.image.load("kagemand/kagemand5.png").convert_alpha(),
    pygame.image.load("kagemand/kagemand6.png").convert_alpha(),
    pygame.image.load("kagemand/kagemand7.png").convert_alpha(),
    pygame.image.load("kagemand/kagemand8.png").convert_alpha()]


for animation_image in kagemand_animation_temp:
    img_rect = animation_image.get_rect()
    animation_image_new = pygame.transform.smoothscale(animation_image, (screen_scale_w(img_rect.w, screen_scale_factor_w), screen_scale_h(img_rect.h, screen_scale_factor_h)) )
    kagemand_animation.append(animation_image_new)


mouse_down = 0

bg = pygame.image.load("background.png").convert_alpha()
bg = pygame.transform.smoothscale(bg, DISPLAYSURF.get_size())

mouse_snowman = Snowman(0, 0)
mouse_snowman.speed = -1
mouse_cakeman = CakeMan(0, 0)
mouse_reindeer = Reindeer(0, 0)

frame_count = 0

# heart_health = pygame.image.load("heart.png")

while True:     
    for event in pygame.event.get():              
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    
    pressed_keys = pygame.key.get_pressed()
    if pressed_keys[K_ESCAPE]:
      sys.exit()

    DISPLAYSURF.blit(bg, (0, 0))
    if heart.lives <= 0:
        DISPLAYSURF.blit(you_died, (screen_scale_w(100, screen_scale_factor_w), screen_scale_h(400, screen_scale_factor_h)))
        pygame.display.update()
        FramePerSec.tick(10)
        frame_count = (frame_count + 1) % 16
        continue

    heart.draw(DISPLAYSURF)

    DISPLAYSURF.blit(exit_text_surface, (exit_text_x, exit_text_y))
    # cakeman.draw(DISPLAYSURF)
    #menu_snowman.update()
    for snowman in snowman_list:
        snowman.draw(DISPLAYSURF, enemy_list)

    for reindeer in reindeer_list:
        reindeer.draw(DISPLAYSURF)
    
    for cakeman in cakeman_list:
        # cakeman.draw(DISPLAYSURF)

        kagemand_image = kagemand_animation[cakeman.animation_step]
        kagemand_rect = kagemand_image.get_rect()
        kagemand_rect.center = cakeman.rect.center
        DISPLAYSURF.blit(kagemand_image, kagemand_rect)
    
        if frame_count == 0:
            cakeman.animation_step = (cakeman.animation_step + 1) % len(kagemand_animation)

            if cakeman.animation_step == 7:
                rect = cakeman.rect
                for enemy in enemy_list:
                    if enemy.alive:
                        if enemy.rect.colliderect(rect):
                            enemy.damage(100)
             

    for enemy in enemy_list:
        if enemy.alive:
            enemy.move(menu_snowman)
            enemy.draw(DISPLAYSURF)
            
            # for cakeman in cakeman_list:
            #     if cakeman.animation_step == 7:
            #      rect = cakeman.rect
            #      # print(rect)
            #      
            #      if enemy.rect.colliderect(rect):
            #          enemy.damage(100)
            #          add_money(1000)

    if event.type == MOUSEBUTTONDOWN:

        if event.button == MOUSE_BUTTON_RIGHT:
            menu_snowman.selected = 0
            menu_cakeman.selected = 0
            menu_reindeer.selected = 0
        else:
            if mouse_down == 0:
                mouse_down = 1
                mouse_pos = event.pos
                # print(mouse_pos)
                
                
                # print("exit rect: " + str(exit_rect))
                if exit_rect.collidepoint(mouse_pos):
                    exit()

                #
                # Menu snowman
                #
                if menu_snowman.selected == 1:

                    if try_to_buy(mouse_snowman, menu_snowman.price):
                        snowman_list.append(Snowman(mouse_pos[0], mouse_pos[1]))
                        # print(len(snowman_list))
                    
                    menu_snowman.selected = 0
                
                
                if menu_snowman.rect.collidepoint(mouse_pos):
                    # print("Clickmenusnowman")
                    if money >= menu_snowman.price:
                        menu_snowman.selected = 1

                #
                # menu cakeman
                #

                if menu_cakeman.selected == 1:

                    if try_to_buy(mouse_cakeman, menu_cakeman.price):
                        mouse_pos = pygame.mouse.get_pos()
                        cakeman_list.append(CakeMan(mouse_pos[0], mouse_pos[1]))
                        # print(len(snowman_list))
                    
                    menu_cakeman.selected = 0
                
                #
                # Menu Reindeer
                #
                if menu_reindeer.selected == 1:

                    if try_to_buy(mouse_reindeer, menu_reindeer.price):
                        mouse_pos = pygame.mouse.get_pos()
                        reindeer_list.append(Reindeer(mouse_pos[0], mouse_pos[1]))
                        # print(len(snowman_list))
                    
                    menu_reindeer.selected = 0


                if menu_cakeman.rect.collidepoint(mouse_pos):
                    if money >= menu_cakeman.price:
                        menu_cakeman.selected = 1


                if menu_reindeer.rect.collidepoint(mouse_pos):
                    if money >= menu_reindeer.price:
                        menu_reindeer.selected = 1


    elif event.type == MOUSEBUTTONUP:
        mouse_down = 0


    if (frame_count % 4) == 0:
        kagemand_animation_step = (kagemand_animation_step + 1) % 8
    
    for snowball in snowball_list:    
        snowball.move(snowball_list, enemy_list)
        snowball.draw(DISPLAYSURF)

    for laser_beam in laser_beam_list:    
        laser_beam.move(menu_snowman)
        laser_beam.draw(DISPLAYSURF)
    
    if menu_snowman.selected == 1:
        if event.type == pygame.MOUSEMOTION:
            mouse_pos = pygame.mouse.get_pos()
            mouse_snowman.rect.center = (mouse_pos[0], mouse_pos[1])
            mouse_snowman.draw(DISPLAYSURF, enemy_list)
    elif menu_cakeman.selected == 1:
        if event.type == pygame.MOUSEMOTION:
            mouse_pos = pygame.mouse.get_pos()
            mouse_cakeman.rect.center = (mouse_pos[0], mouse_pos[1])
            mouse_cakeman.draw(DISPLAYSURF)
    elif menu_reindeer.selected == 1:
        if event.type == pygame.MOUSEMOTION:
            mouse_pos = pygame.mouse.get_pos()
            mouse_reindeer.rect.center = (mouse_pos[0], mouse_pos[1])
            mouse_reindeer.draw(DISPLAYSURF)


    #DISPLAYSURF.fill(WHITE)
    menu_snowman.draw(DISPLAYSURF)
    menu_cakeman.draw(DISPLAYSURF)
    menu_reindeer.draw(DISPLAYSURF)
    
    
    DISPLAYSURF.blit(text_surface, (text_surface_x, text_surface_y))
    DISPLAYSURF.blit(level_text_surface, (level_text_surface_x, level_text_surface_y))

    frame_count = (frame_count + 1) % 16

    if (check_round_end()):
        level_up()

    pygame.display.update()
    FramePerSec.tick(FPS)
    
