"""
credits screen
"""


import sys

from OpenGL.GL import *
from OpenGL.GLU import *
import pygame, pygame.image
from pygame.locals import *

import texMgr
import draw_util
import gui_widgets as gw

import fsm_mgr as fsm
import tubeMgr

import levels


SCROLL_TIME=40.0


class StateCredits(fsm.State):
    def __init__(self):
        fsm.State.__init__(self)

        texMgr.loadTexture("data/credits.png", "credits")
        
        self.timeNow=0

    def init(self, unused_args):
        self.timeNow=0

    def draw(self):
        glClearColor(0.0, 0.0, 0.0, 1.0)
        glClear(GL_COLOR_BUFFER_BIT)

        initPos=0.0
        finalPos=1600+600.0

        fracTime=self.timeNow/SCROLL_TIME

        fracTime=min(fracTime,1.0)
        
        posNow=initPos+(finalPos-initPos)*fracTime
        draw_util.draw_quad("credits", 0, posNow, 800, posNow-1600.0)


    def handleKey(self, key, unicode):
        self.endState()
        return True

    def handleMouseButton(self, bDown, buttonIndex):
        if bDown:
            self.endState()
        return True

    def endState(self):
        fsm.popState()
        
    def update(self, dt):
        self.timeNow += dt

        if self.timeNow >= SCROLL_TIME:
            self.endState()
            
        return True
        
        
