"""
events.py - Handles all interactive events
"""

import common
import pygame
import levels
from pygame.locals import *

def handleAll():
    for x in pygame.event.get([KEYUP,KEYDOWN,QUIT]):
        if x.type == KEYDOWN:
            if x.key == K_ESCAPE:
                common.game_finished = 1
            elif x.key == K_p:
                if common.game_paused:
                    common.game_paused = 0
                else: common.game_paused = 1
            elif common.game_paused:
                common.game_paused = 0
        elif x.type == QUIT:
            common.game_finished = 1

    # reset key states
    common.key_state = pygame.key.get_pressed()

    if common.game_paused:
        levels.showPause()
        while not pygame.event.peek([KEYDOWN]):
            pass
        levels.hidePause()
                
