"""
main menu 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


ROLL_TIME=3.0
HOLD_TIME=1.0


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

        texMgr.loadTexture("data/intro/bdg.png", "splash_bdg")
        
        self.timeNow=0

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

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

        initPos=800
        finalPos=200

        initAngle=-3.0 #radians
        finalAngle=0.0 #radians

        fracTime=self.timeNow/ROLL_TIME

        fracTime=min(fracTime,1.0)
        
        posNow=initPos+(finalPos-initPos)*fracTime
        rotNow=initAngle+(finalAngle-initAngle)*fracTime
        draw_util.draw_rot_quad("splash_bdg", posNow, 500, posNow+400, 100, rotNow)


    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 >= ROLL_TIME+HOLD_TIME:
            self.endState()
            
        return True
        
        
