require "fade"
require "game"
require "mapa"
require "scenes"

intro_wait=40
intro_step=0

function intro_init()
    game_update = intro_intro
    intro_wait=400
    surf.cls(16)
    surf.target(logo)
    surf.cls(16)
    draw.text("JAILGAMES",0,0,15)
    surf.target(0)
    surf.source(logo)
    draw.surf(0,0,36,5,28,35,72,10)
    surf.source(tiles)
    fade.fadein()
end

function intro_intro()
    --text("JAILGAMES",40,30,15)
    text("presenta",48,50,14)
    intro_wait=intro_wait-1
    if intro_wait==0 or key.press(key.ESCAPE) or key.press(keyShoot) or pad.press(btnShoot) or pad.press(btnPause) then
        intro_wait=1
        game_update = intro_update
        fade.fadeoutin()
    end
end

function intro_update()
    if key.press(key.ESCAPE) or pad.press(btnPause) then
        game_init(true)
        fade.fadeoutin()
    elseif key.press(key.SPACE) then
        intro_wait=1
    end

    intro_wait=intro_wait-1
    if intro_wait==0 then
        if intro_step==0 then
            surf.cls(16)
            draw.rect(15,3,99,51,2)
            view.origin(16,4)
            mapa_draw(10)
            draw.rectf(73,24,7,16,16)
            draw.surf(0,0,16,16,44,24,16,16,true)
            view.origin(0,0)
            intro_step=intro_step+1
        elseif intro_step==1 then
            start_scene(scenes.intro_01,58)
            intro_step=intro_step+1
        elseif intro_step==2 then
            surf.cls(16)
            draw.rect(15,3,99,51,2)
            view.origin(16,4)
            mapa_draw(10)
            draw.rectf(73,24,7,16,16)
            draw.surf(0,0,16,16,44,24,16,16,false)
            view.origin(0,0)
            intro_step=intro_step+1
        elseif intro_step==3 then
            start_scene(scenes.intro_02,58)
            intro_step=intro_step+1
        elseif intro_step==4 then
            surf.cls(16)
            draw.rect(15,3,99,51,2)
            view.origin(16,4)
            mapa_draw(10)
            draw.rectf(73,24,7,16,16)
            draw.surf(0,0,16,16,44,24,16,16,false)
            draw.surf(112,88,16,8,76,32,16,8,true)
            draw.surf(0,48,16,16,82,24,16,16,true)
            view.origin(0,0)
            intro_step=intro_step+1
        elseif intro_step==5 then
            start_scene(scenes.intro_03,58)
            intro_step=intro_step+1
        elseif intro_step==6 then
            surf.cls(16)
            draw.rect(15,3,99,51,2)
            view.origin(16,4)
            mapa_draw(10)
            draw.rectf(73,24,7,16,16)
            draw.surf(0,0,16,16,44,24,16,16,false)
            view.origin(0,0)
            intro_step=intro_step+1
        elseif intro_step==7 then
            start_scene(scenes.intro_04,58)
            intro_step=intro_step+1
        elseif intro_step==8 then
            music.play(audio_main_song)
            game_init(true)
            fade.fadeoutin()
        end
        intro_wait=50
    end
end