stage1_boss ={
    time = 0,
}

function stages.stage1_boss_ready()
    print("READY")
    stages.boss_ready = true
    stages.boss_finished = false
end

-- function stages.stage1_boss()
--     -- if not scene.running and not stages.boss_loaded then
--         load_tilemap( sf_mapa, stage1_boss_mapa )
--         -- actors_in_room_backup_and_remove(stage1_boss_mapa.r0.r,stage1_boss_mapa.r1.r)
--         -- viewp:fixed({l=8,r=44,u=48,d=0}, viewp.x, viewp.y-48)
--         -- viewp:fixed({l=8,r=44,u=0,d=0})
--         stages.boss_loaded = true
--         boss.reason=""
--         boss.enabled=true
--         boss:fight()
--         trigger_event.new("Premiere Boss 1",
--                            trigger_ev.premiere_boss1_trigger, 
--                            trigger_ev.premiere_healer_init, 
--                            premiere.healer_update)
--     -- end
-- end

function stages.stage1_boss_update()
    -- print("stage1_update")
    fireball.update()
    -- if (abad.energia<=abad.max_energia/2) then
    --     -- Requeriment: tindre mitja clau
    --     premiere.healer_init()
    -- end
end

function stages.stage1_boss_draw_back()
    -- print("stage1_draw_back")
end

function stages.stage1_boss_draw_middle()
    -- print("stage1_draw_middle")
end

function stages.stage1_boss_draw_front()
    -- print("stage1_draw_front")
    fireball.draw()
    boss_meter:draw()
end

function stages.stage1_boss_finished()
    stages.boss_ready = true
    stages.boss_finished = true
end

-- function stages.stage1_boss_end()
--     mapa_restore_backup()
--     set_actors_enabled_by_room(true, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
--     remove_actor(boss)
--     stages.boss_ready = false
--     stages.boss_finished = false
--     stages.boss_loaded = false
--     viewp:free_move()
-- end


-- INTRO FUNCTIONS
function stages.stage1_boss_intro_init()
    trigger_event.new("Premiere Boss 1",
                       trigger_ev.premiere_boss1_trigger, 
                       trigger_ev.premiere_healer_init, 
                       premiere.healer_update)
    load_tilemap( sf_mapa, stage1_boss_mapa )
    set_actors_enabled_by_room(false, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
    viewp:fixed({l=8,r=44,u=0,d=0}, viewp.x, viewp.y-48)
    boss.enabled=true
    boss.reason=""
    boss:fight()
    load_boss_stage()
    stages.boss_loaded = true
    states:next()
end

function stages.stage1_boss_intro_update()
    if stage1_boss.time==0 then
        start_scene(scenes.lluita_imp, nil, false)
        stages.stage1_boss_ready()
    end
    
    -- Acabar
    if stage1_boss.time>=1 then
        states:next()
    end
    
    stage1_boss.time = stage1_boss.time + 1
end

function stages.stage1_boss_intro_end()
    states:finish()
end

-- OUTRO FUNCTION
function stages.stage1_boss_outro_update()
    stage1_boss.time = stage1_boss.time + 1
    
    states:next()
end

function stages.stage1_boss_outro_end()
    stages.stage1_boss_finished()
    remove_actor(boss)
    unload_boss_stage()
    music.stop()
    mapa_restore_backup()
    set_actors_enabled_by_room(true, "boss", stage1_boss_mapa.r0.r, stage1_boss_mapa.r1.r)
    stages.boss_ready    = false
    stages.boss_finished = false
    stages.boss_loaded   = false
    viewp:free_move()   
    states:finish()
end


-- STATES REGISTRY
states:registrar("stage1_boss_intro",{
    stages.stage1_boss_intro_init,
    stages.stage1_boss_intro_update,
    stages.stage1_boss_intro_end
})

states:registrar("stage1_boss_outro",{
    stages.stage1_boss_outro_update,
    stages.stage1_boss_outro_end
})