import sys
import rabbyt
from pyglet.clock import Clock
from pyglet.gl import *

class Intro:
    def __init__(self, window):
        clock = Clock()
        clock.set_fps_limit(60)
        time = 0
        rabbyt.set_time(time)

        #b1 = rabbyt.Sprite(shape=(-512,0,512,-150), rgb=(0,0,0), y=768/2)
        #b2 = rabbyt.Sprite(shape=(-512,150,512,0), rgb=(0,0,0), y=-768/2)
        #self.sprites = [b1, b2]

        self.running = True


        #def scene1(dt):
            #bg = rabbyt.Sprite("movie/island_bg.png")
            #bg.scale = rabbyt.lerp(start=1, end=3, dt=7)

            #w = rabbyt.Sprite("movie/wheel.png", x=-200)
            #w.rot = rabbyt.lerp(start=359, end=0, dt=12, extend="repeat")
            #w.scale = rabbyt.lerp(start=1, end=3, dt=7)

            #c = rabbyt.Sprite("movie/claw.png", y=1300)
            #c.y = rabbyt.lerp(startt=dt+2, dt=1, end=-1300)
            #c.scale = rabbyt.lerp(start=1, end=3, dt=7)

            #self.sprites = [bg, w, c, b1, b2]
        #scene1(0)


        #def scene2(dt):
            #bg = rabbyt.Sprite(shape=(1024, 468), rgba=(1,209/255.,155/255.,0))
            #bg.alpha = rabbyt.ease_in(end=1, dt=3)
            #bg.rgb = rabbyt.ease_in(startt=dt+3.5, end=(1,1,1), dt=.2)
            #self.sprites = [bg]
        #clock.schedule_once(scene2, 3.1)


        #def scene3(dt):
            #bg = rabbyt.Sprite(shape=(1024, 468), rgba=(1,1,1,1))
            #bg.alpha = rabbyt.ease_out(startt=dt+.2, end=0, dt=1)

            #sky1 = rabbyt.Sprite("movie/sky1.png")
            #cbl1 = rabbyt.Sprite("movie/cables.png")
            #tree1 = rabbyt.Sprite("movie/tree1.png")
            #g1 = rabbyt.Sprite("movie/gondola1.png")

            #cam_move_1_dt = 9

            #tree1.x = rabbyt.ease_out(start=-350, end=-500, dt=cam_move_1_dt)
            #tree1.y = rabbyt.ease_out(start=-100, end=-150, dt=cam_move_1_dt)
            #tree1.scale = rabbyt.ease_out(start=.8, end=1, dt=cam_move_1_dt)

            #cbl1.y = rabbyt.ease_out(start=100, end=60, dt=cam_move_1_dt)

            #g1.y = cbl1.attrgetter("y")-45
            #g1.x = -200

            #b1.scale_y = rabbyt.lerp(startt=dt+cam_move_1_dt, end=3, dt=.5)
            #b2.scale_y = rabbyt.lerp(startt=dt+cam_move_1_dt, end=3, dt=.5)

            #self.sprites = [sky1, cbl1, tree1, g1, bg, b1, b2]
        #scene3(0)
        #clock.schedule_once(scene3, 3+4)

        def loading(dt):
            bg = rabbyt.Sprite("movie/loading.png")
            self.sprites = [bg]

            #def end(dt):
                #self.running = False
            #clock.schedule_once(end, 1)
        loading(0)
        #clock.schedule_once(loading, 10)#3+4+10)



        while self.running:
            if window.has_exit:
                sys.exit(0)

            time += clock.tick()
            window.dispatch_events()
            rabbyt.clear((0,0,0))
            rabbyt.set_time(time)

            l = -window.width/2
            t = window.height/2
            r = window.width/2
            b = -window.height/2
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glOrtho(l, r, b, t, -1000, 1000)
            glMatrixMode(GL_MODELVIEW)
    
            rabbyt.render_unsorted(self.sprites)

            window.flip()
            self.running = False

        l = 0
        t = window.height
        r = window.width
        b = 0
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(l, r, b, t, -1000, 1000)
        glMatrixMode(GL_MODELVIEW)
