import pygame
from pygame.locals import *
from pygame import mixer 
from random import *

pygame.init()
running=True
screen_width, screen_height=1200, 900
screen= pygame.display.set_mode((screen_width, screen_height))
snowflakeList=[]
moving=False
global movingElement
#bg music
mixer.music.load("music.wav")
mixer.music.play(-1)

#bg picture
bg=pygame.image.load("bg.png")

#tree image
tree= pygame.image.load("tree.png")
tree_loc=tree.get_rect()
tree_loc.center=screen_width/2, screen_height/2

#santa
santa=pygame.image.load("santa.png")
santa_loc= santa.get_rect()
santa_loc.center=100, screen_height/2

#snowflake
snowflake_img=pygame.image.load("snowflake.png")
for n in range(20):
    image_loc = snowflake_img.get_rect()
    image_loc.x = randint(0, screen_width-10)
    image_loc.y = randint(-50, screen_height)
    snowflakeList.append(image_loc)

#toy images
images = ["star.png", "red.png", "green.png","blue.png", "bell.png", "gold.png", "gold2.png"]
toys=[]
# load images
for index, image_name in enumerate(images, start=1):
    img=pygame.image.load(image_name)
    img_loc=img.get_rect()
    img_loc.center=screen_width*0.9, index*screen_height/9
    toys.append([img, img_loc])

while running:
    santa_loc.x+=1
    if santa_loc.x>screen_width:
        santa_loc.x=-300

    #display objects
    screen.fill("sky blue")
    screen.blit(bg, [0, screen_height/3])
    screen.blit(santa, santa_loc)
    screen.blit(tree, tree_loc)
    for toy in toys:
        screen.blit(toy[0], toy[1])

    #display multiple snowflakes     
    for snowflake in snowflakeList:
        screen.blit(snowflake_img, snowflake)
        snowflake.y+=randint(1,5)
        if snowflake.y>screen_height:
            snowflake.x=randint(0, screen_width-10)
            snowflake.y=-50


    pygame.display.update()

    for event in pygame.event.get():
        if event.type==QUIT:
            running=False
        elif event.type==MOUSEBUTTONDOWN:
            for toy in toys:
                toy_loc=toy[1]
                if toy_loc.collidepoint(event.pos):
                    moving=True
                    movingElement=toy
        elif event.type==MOUSEBUTTONUP:
            moving=False
            movingElement=None
        elif event.type==MOUSEMOTION and moving:
            movingElement[1].move_ip(event.rel)
            screen.blit(movingElement[0], movingElement[1])
            pygame.display.update()

pygame.quit()