# -*- coding: utf-8 -*-
from __future__ import division, print_function

import logging

import pygame.event

logger = logging.getLogger(__name__)


class Intro:

    def __init__(self):
        pass

    def run(self, images, music):
        screen = pygame.display.get_surface()

        img = images.pop(0)

        pygame.mixer.music.load(music)
        pygame.mixer.music.set_volume(0.3)
        pygame.mixer.music.play()

        pygame.event.clear()
        clock = pygame.time.Clock()
        running = True
        while running:
            clock.tick(60)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
                    elif event.key == pygame.K_SPACE:
                        if images:
                            img = images.pop(0)
                        else:
                            running = False

            screen.blit(img, (0, 0))
            pygame.display.flip()

        pygame.mixer.music.fadeout(500)
