GameScreen.textures_path = "graphics/screens/13_lasers/location/"

GameScreen.inv_fun = {}
GameScreen.inv_fun["hand_mirror_010"] = function()
    --Inventory:ClueAndHide() 
    ItemSetOpacity(Inventory.drag_obj.icon, 0.0)
    DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "drag_mirror_name", "graphics/interface/tools/hand_mirror_inv", -100, -100);
    local mirror = {}
    mirror.name = "drag_mirror_name"
    CurrentScreen.drag_mirror =  CurrentScreen:__create_drag_mirror(mirror, true)
    clApplication.lock_cursor = false;
    SetVisibleCursor(false)
    DelayedExec(0.01, function()
        can_drop = true
    end, 113)
end

function GameScreen:RestoreScene()
    self:__emitters_init();
    self:__init_lasers();
    self:__places_init();
    self:__mirrors_init(); 
    
    if(GetState(CURRENT_SCREEN, "state") == "finish") then
        SetState("screen_chapters_screen", "current_chapter", "4")
        clApplication:LoadLocation("Intro_03")
    end 
    
    for found_item in string.gmatch(GetState(CURRENT_SCREEN, "found_obj"), "[_%a%d]+") do
		ItemRemove(self.name, found_item)
		ItemRemove(self.name, found_item.."_shadow")
    end 
end

function GameScreen:InitScreen()
    self:LoadScreen()

   --Inventory:add_tool("hand_mirror_010")
    
    
    self:AddHiddenCrystal("crystal_13_part")
    self:RestoreScene();
    
    HUDScreen:ShowTips({path = "graphics/screens/13_lasers/location/Text_13", x = 452, y = 1130})
    
    MusicPlay({"sound/ambient/13_ambient.ogg", "sound/music/portal_active.ogg"}, 13) 
end   
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:__mirrors_init()
    self.mirrors = {}
    for i = 1, 15 do
        self.mirrors[i] = {}
        self.mirrors[i].name = "mirror_"..i;
        self.mirrors[i].active = true;
        if(GetState(CURRENT_SCREEN, "mirror_"..i) == "1") then
            self.mirrors[i].active = false;
            ItemRemove(self.name, "mirror_"..i)
            ItemRemove(self.name, "mirror_"..i.."_shadow")
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:__get_mirror_by_name(item_name)
    for key, value in pairs(self.mirrors) do
        if(value.name == item_name) then
            return value;
        end
    end
    
    return nil
end
------------------------------------------------------------------------------------------------------
function GameScreen:__create_drag_mirror(mirror, is_hand_mirror)
    if(is_hand_mirror) then
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_floor", "graphics/screens/13_lasers/location/hand_mirror_floor", -100, -100);
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_ceiling", "graphics/screens/13_lasers/location/hand_mirror_ceiling", -100, -100);
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_left", "graphics/screens/13_lasers/location/hand_mirror_left", -100, -100);
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_right", "graphics/screens/13_lasers/location/hand_mirror_right", -100, -100);
    else
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_right", "graphics/screens/13_lasers/location/wall_right_mirror", -100, -100);
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_left", "graphics/screens/13_lasers/location/wall_left_mirror", -100, -100);
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_floor", "graphics/screens/13_lasers/location/floor_mirror", -100, -100);
        DragObject:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_ceiling", "graphics/screens/13_lasers/location/ceiling_mirror", -100, -100);
    end
    ItemSetOpacity("mirror_floor", 0.0)
    ItemSetOpacity("mirror_ceiling", 0.0)
    ItemSetOpacity("mirror_left", 0.0)
    ItemSetOpacity("mirror_right", 0.0)
    
    local drag_mirror = {}
    drag_mirror = mirror;
    drag_mirror.mirror_floor = "mirror_floor";
    drag_mirror.mirror_ceiling = "mirror_ceiling";
    drag_mirror.mirror_left = "mirror_left";
    drag_mirror.mirror_right = "mirror_right";
    if(is_hand_mirror) then
        drag_mirror.start_pos = {x = 50, y = 50}
    else
        drag_mirror.start_pos = {x = ItemGetX(drag_mirror.name), y = ItemGetY(drag_mirror.name)}
    end
    ItemSetType(drag_mirror.name, OBJ_TYPE.NO_ACTIVE)
    
    return drag_mirror;
end
------------------------------------------------------------------------------------------------------
function GameScreen:__drag_mirror_placed(place_name)
    ItemRemove(self.name, self.drag_mirror.mirror_floor)
    ItemRemove(self.name, self.drag_mirror.mirror_ceiling)
    ItemRemove(self.name, self.drag_mirror.mirror_left)
    ItemRemove(self.name, self.drag_mirror.mirror_right)
    ItemRemove(self.name, self.drag_mirror.name)
    
    SetState(CURRENT_SCREEN, self.drag_mirror.name, "1")
    
    SoundPlay("sound/laser_mirror.ogg")
    
    if(self.drag_mirror.name == "drag_mirror_name") then
        SetState(CURRENT_SCREEN, place_name, "4")
        self.places[place_name] = 4
        self:set_mirror_in_place(place_name, 2)
        SetVisibleCursor(true)
        Inventory:ActiveToolApply()
    else
        SetState(CURRENT_SCREEN, place_name, "2")
        self.places[place_name] = 2
        self:set_mirror_in_place(place_name, 1)
    end
    
    self:update_lasers()
    self.drag_mirror = nil;
end
------------------------------------------------------------------------------------------------------
function GameScreen:__drag_mirror_return()
    ItemRemove(self.name, self.drag_mirror.mirror_floor)
    ItemRemove(self.name, self.drag_mirror.mirror_ceiling)
    ItemRemove(self.name, self.drag_mirror.mirror_left)
    ItemRemove(self.name, self.drag_mirror.mirror_right)
    ItemSetOpacity(self.drag_mirror.name, 1.0)
    ItemSetType(self.drag_mirror.name, OBJ_TYPE.ACTIVE_ALL)
    
    ItemMoveTo(self.drag_mirror.name, self.drag_mirror.start_pos.x, self.drag_mirror.start_pos.y, 0.5)
   
    self.drag_mirror = nil;
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:__init_lasers()
    local lasers_name = {"laser_09c", "laser_09b", "laser_09a", "laser_09", "laser_07c", "laser_07b", "laser_07a", "laser_07",
                         "laser_06b", "laser_06a", "laser_06", "laser_08", "laser_08_04", "laser_04_08", "laser_04", "laser_03",
                         "laser_02_03", "laser_02", "laser_05", "laser_05_01", "laser_01_05", "laser_01"}

    self.lasers = {}
     
    for key, value in pairs(lasers_name) do
        local laser = {}
        laser.name = value;
        laser.state = 0;
        table.insert(self.lasers, laser)
    end
    
    self.lasers[1].parent = {{"ceiling_01_insert", "wall_right_03_insert", "floor_02_insert", "emitter_09"}}
    self.lasers[2].parent = {{"wall_right_03_insert", "floor_02_insert", "emitter_09"}}
    self.lasers[3].parent = {{"floor_02_insert", "emitter_09"}}
    self.lasers[4].parent = {{"emitter_09"}}
    self.lasers[5].parent = {{"wall_right_04_insert", "wall_left_04_insert", "wall_right_05_insert", "emitter_07"}}
    self.lasers[6].parent = {{"wall_left_04_insert", "wall_right_05_insert", "emitter_07"}}
    self.lasers[7].parent = {{"wall_right_05_insert", "emitter_07"}}
    self.lasers[8].parent = {{"emitter_07"}}
    self.lasers[9].parent = {{"wall_left_05_insert", "wall_right_02_insert", "emitter_06"}}
    self.lasers[10].parent = {{"wall_right_02_insert", "emitter_06"}}
    self.lasers[11].parent = {{"emitter_06"}}
    self.lasers[12].parent = {{"emitter_08"}}
    self.lasers[13].parent = {{"emitter_08", "wall_right_01_insert"}, {"floor_03_insert", "emitter_04", "wall_left_03_insert"}}
    self.lasers[14].parent = {{"emitter_08", "wall_right_01_insert", "floor_03_insert"}, {"emitter_04", "wall_left_03_insert"}}
    self.lasers[15].parent = {{"emitter_04"}}
    self.lasers[16].parent = {{"emitter_03"}}
    self.lasers[17].parent = {{"emitter_03", "floor_04_insert"}, {"emitter_02", "wall_left_02_insert"}}
    self.lasers[18].parent = {{"emitter_02"}}
    self.lasers[19].parent = {{"emitter_05"}}
    self.lasers[20].parent = {{"emitter_05", "ceiling_02_insert"}, {"wall_left_01_insert", "emitter_01", "floor_01_insert"}}
    self.lasers[21].parent = {{"emitter_05", "ceiling_02_insert", "wall_left_01_insert"}, {"emitter_01", "floor_01_insert"}}
    self.lasers[22].parent = {{"emitter_01"}}
    
   -- self:update_lasers();
    
end    

function GameScreen:is_active_laser(item_name)
    for key1, laser in pairs(self.lasers) do
        if(laser.name == item_name and laser.state == 1) then
            return true;
        end
    end
    
    return false
end

function GameScreen:update_lasers()
    --расставим зеркала
    for key1, laser in pairs(self.lasers) do
        ItemSetOpacity(laser.name, 0.0)
        laser.state = 0;
        for key2, parents in pairs(laser.parent) do   
            local flag = true;
            for key3, parent_name in pairs(parents) do   
                if(not self:__is_emitter(parent_name) and (not self.places[parent_name] or self.places[parent_name] == 1))then
                    flag = false
                end
            end
            if(flag) then
                laser.state = 1;
                ItemSetOpacity(laser.name, 1.0)
            end
        end
    end
    
    if(self.places["ceiling_02_insert"] > 1 and self.places["wall_left_01_insert"] > 1 and self.places["floor_01_insert"] > 1)then
        self:__emitter_destroy(1)
        self:__emitter_destroy(5)
    end
    if(self.places["wall_left_02_insert"] > 1 and self.places["floor_04_insert"] > 1)then
        self:__emitter_destroy(2)
        self:__emitter_destroy(3)
    end
    
    if(self.places["wall_left_03_insert"] > 1 and self.places["floor_03_insert"] > 1 and self.places["wall_right_01_insert"] > 1)then
        self:__emitter_destroy(4)
        self:__emitter_destroy(8)
    end
    
    if(self.places["wall_right_02_insert"] > 1 and self.places["wall_left_05_insert"] > 1)then
        self:__emitter_destroy(6)
    end
    
    if(self.places["wall_right_05_insert"] > 1 and self.places["wall_right_04_insert"] > 1 and self.places["wall_left_04_insert"] > 1)then
        self:__emitter_destroy(7)
    end
    
    if(self.places["wall_right_03_insert"] > 1 and self.places["floor_02_insert"] > 1 and self.places["ceiling_01_insert"] > 1)then
        self:__emitter_destroy(9)
    end
    
    if(self:IsMinigameCompleted()) then
        HUDScreen:SetInvntoryOnlyMode()
        DelayedExec(1.0, function()
            self:OnFinish();
        end, 113)
    end
end
------------------------------------------------------------------------------------------------------
-----------------------------------------------------eitters----------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:__emitters_init()
    self.emitters = {}
    for i = 1, 9 do
        self.emitters["emitter_0"..i] = true
        ItemSetOpacity("emitter_0"..i, 0.0)
        if(GetState(CURRENT_SCREEN, "emitter_0"..i) == "1") then
            self.emitters["emitter_0"..i] = false
            ItemSetOpacity("emitter_0"..i, 1.0)
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:IsMinigameCompleted()
    for i = 1, 9 do
        if(self.emitters["emitter_0"..i] == true) then
            return false
        end
    end
    
    return true;
end
------------------------------------------------------------------------------------------------------
function GameScreen:__is_emitter(item_name)
    if(self.emitters[item_name] == true) then
        return true;
    end 
    return false;
end

function GameScreen:__emitter_destroy(emitter_id)
    if(self.emitters["emitter_0"..emitter_id] == true) then
        DelayedExec(0.5, function()
            self:CreateAnim(OBJ_TYPE.NO_ACTIVE, "emitter_explosion_"..emitter_id, "graphics/screens/13_lasers/location/emitter_explosion", -100, -100);
            local _x = ItemGetX("emitter_0"..emitter_id) + ItemGetWidth("emitter_0"..emitter_id) / 2 - ItemGetWidth("emitter_explosion_"..emitter_id) / 2;
            local _y = ItemGetY("emitter_0"..emitter_id) + ItemGetHeight("emitter_0"..emitter_id) / 2 - ItemGetHeight("emitter_explosion_"..emitter_id) / 2;
            ItemSetPosition("emitter_explosion_"..emitter_id, _x, _y) 
            DelayedExec(2.0, 
                function() ItemRemove(self.name, "emitter_explosion_"..emitter_id) 
            end, 113)
            SoundPlay("sound/emitter_explosion.ogg")
            ItemChangeOpacity("emitter_0"..emitter_id, 1.0, 0.5)
            self.emitters["emitter_0"..emitter_id] = false
        end, 113)
        DelayedExec(1.0, function()
            self:update_lasers()
        end, 113)
    elseif(self.emitters["emitter_0"..emitter_id] == false) then
        ItemSetOpacity("emitter_0"..emitter_id, 1.0)
        SetState(CURRENT_SCREEN, "emitter_0"..emitter_id, "1")
    end 
end

------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
--1. - пусто
--2. - вставили обычное зеркало
--3. - обычное зеркало уже стоит
--4. - вставили зеркало с ручкой
--5. - зеркало с ручкой уже стоит
function GameScreen:__places_init()
    self.places = {}
    self.places["wall_right_01_insert"] = 1;
    self.places["wall_right_02_insert"] = 1;
    self.places["wall_right_03_insert"] = 1;
    self.places["wall_right_04_insert"] = 1;
    self.places["wall_right_05_insert"] = 1;
    self.places["wall_left_04_insert"] = 1;
    self.places["wall_left_05_insert"] = 1;
    self.places["floor_02_insert"] = 1;
    self.places["ceiling_01_insert"] = 1;
    self.places["wall_left_03_insert"] = 1;
    self.places["floor_03_insert"] = 1;
    self.places["wall_left_02_insert"] = 1;
    self.places["floor_04_insert"] = 1;
    self.places["ceiling_02_insert"] = 1;
    self.places["wall_left_01_insert"] = 1;
    self.places["floor_01_insert"] = 1;

    for key, value in pairs(self.places) do
        if(GetState(CURRENT_SCREEN, key) ==  "2") then
            self:set_mirror_in_place(key, 1)
            self.places[key] = 2
        end
        if(GetState(CURRENT_SCREEN, key) ==  "4") then
            self:set_mirror_in_place(key, 2)
            self.places[key] = 4
        end
    end
    
    self:update_lasers()
end
------------------------------------------------------------------------------------------------------
function GameScreen:set_mirror_in_place(place_name, type)
    local place_type = self:__get_place_type(place_name)
    local x = ItemGetX(place_name)
    local y = ItemGetY(place_name)
    
    if(place_type == "right") then
        if(type == 1) then
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/wall_right_mirror", x, y);
        else
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/hand_mirror_right", x, y);
        end
    elseif(place_type == "left") then
        if(type == 1) then
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/wall_left_mirror", x, y);
        else
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/hand_mirror_left", x, y);
        end
    elseif(place_type == "floor") then
        if(type == 1) then
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/floor_mirror", x, y);
        else
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/hand_mirror_floor", x, y);
        end
    elseif(place_type == "ceiling") then
        if(type == 1) then
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/ceiling_mirror", x, y);
        else
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "mirror_bg", "graphics/screens/13_lasers/location/hand_mirror_ceiling", x - 5, y - 45);
        end
    end
    ItemSetColor("mirror_bg", 0.3, 0.3, 0.3)
    ItemSetDepthByOther("mirror_bg", "13_lasers")
 end
------------------------------------------------------------------------------------------------------
function GameScreen:__get_place_by_name(place_name)
    for key, value in pairs(self.places) do
        if(key == place_name and self.places[key] < 2) then
            return value;
        end
    end
    
    return nil
end
------------------------------------------------------------------------------------------------------
function GameScreen:__get_place_type(place_name)
    if(string.find(place_name, "right") ~= nil) then
        return "right";
    end
    if(string.find(place_name, "left") ~= nil) then
        return "left";
    end
    if(string.find(place_name, "floor") ~= nil) then
        return "floor";
    end
    if(string.find(place_name, "ceiling") ~= nil) then
        return "ceiling";
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:__drag_item_set_state(visible_type)
    ItemSetOpacity(self.drag_mirror.name, 0.0)
    ItemSetOpacity(self.drag_mirror.mirror_floor, 0.0)
    ItemSetOpacity(self.drag_mirror.mirror_ceiling, 0.0)
    ItemSetOpacity(self.drag_mirror.mirror_left, 0.0)
    ItemSetOpacity(self.drag_mirror.mirror_right, 0.0)
    
    ItemSetOpacity(visible_type, 1.0)    
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------ 
------------------------------------------------------------------------------------------------------
function GameScreen:onObjectClick(item_name)
    if(self.active == false) then return end
    
    if(self.drag_mirror) then
        DragObject.active = false;
        SetVisibleCursor(true)
        local place = self:__get_place_by_name(item_name)
        if(place) then
            self:__drag_mirror_placed(item_name)
        else
            SoundPlay("sound/interface/wrong.ogg")
            if(self.drag_mirror.name ~= "drag_mirror_name") then 
                self:__drag_mirror_return()
            else
                --self:__drag_mirror_return()
                if(can_drop) then
                    can_drop = false
                    ItemRemove(self.name, self.drag_mirror.name)
                    ItemRemove(self.name, self.drag_mirror.mirror_floor)
                    ItemRemove(self.name, self.drag_mirror.mirror_ceiling)
                    ItemRemove(self.name, self.drag_mirror.mirror_left)
                    ItemRemove(self.name, self.drag_mirror.mirror_right)
                    self.drag_mirror = nil;
                end
                SetVisibleCursor(false)
            end
        end
    else
        local mirror = self:__get_mirror_by_name(item_name)
        if(mirror) then
            DragObject.active = true;
            self.drag_mirror = self:__create_drag_mirror(mirror)
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:OnMouseMove(item_name)
    if(self.drag_mirror) then
        if(item_name == "floor") then
            self:__drag_item_set_state(self.drag_mirror.mirror_floor)
        elseif(item_name == "ceiling") then
            self:__drag_item_set_state(self.drag_mirror.mirror_ceiling)
        elseif(item_name == "wall_right") then
            self:__drag_item_set_state(self.drag_mirror.mirror_right)
        elseif(item_name == "wall_left") then
            self:__drag_item_set_state(self.drag_mirror.mirror_left)
        elseif(item_name == "13_lasers") then
            self:__drag_item_set_state(self.drag_mirror.name)
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:OnSkip()
    HUDScreen:SetInvntoryOnlyMode()
    Inventory:remove_tool("hand_mirror_010")
    self.active = false;
    
    for key, value in pairs(self.places) do
        if(self.places[key] < 2) then
            self.places[key] = 2
        end
    end
    self:update_lasers()
end
------------------------------------------------------------------------------------------------------
function GameScreen:OnMouseEnter(item_name)
    if(self:is_active_laser(item_name)) then
        SoundPlay("sound/laser_over_sphere_32.ogg")
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:Update()
    if(clApplication.game_pause) then return end
    
    if(self.drag_mirror) then
        if(self.drag_mirror.name == "drag_mirror_name") then
            SetVisibleCursor(false)
            ItemSetPosition(self.drag_mirror.name, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.name) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.name) / 3.5)
        
            ItemSetPosition(self.drag_mirror.mirror_floor, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_floor) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_floor) / 3.5)
            ItemSetPosition(self.drag_mirror.mirror_ceiling, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_ceiling) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_ceiling) / 3.5)
            ItemSetPosition(self.drag_mirror.mirror_left, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_left) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_left) / 3.5)
            ItemSetPosition(self.drag_mirror.mirror_right, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_right) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_right) / 3.5)
        else
            ItemSetPosition(self.drag_mirror.name, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.name) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.name) / 2)
        
            ItemSetPosition(self.drag_mirror.mirror_floor, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_floor) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_floor) / 2)
            ItemSetPosition(self.drag_mirror.mirror_ceiling, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_ceiling) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_ceiling) / 2)
            ItemSetPosition(self.drag_mirror.mirror_left, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_left) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_left) / 2)
            ItemSetPosition(self.drag_mirror.mirror_right, messenger_table.mouse_X - ItemGetWidth(self.drag_mirror.mirror_right) / 2, messenger_table.mouse_Y - ItemGetHeight(self.drag_mirror.mirror_right) / 2)
        end
    end 
end
------------------------------------------------------------------------------------------------------
function GameScreen:OnFinish()
    if(self.finish) then return end
    self.finish = true;
    
    ItemMove("circle_01", 0, -1000, 2.0)
    ItemChangeOpacity("cover_01", 0.0, 2.0)
    SoundPlay("sound/sphere.ogg")
    ItemMove("circle_02", 0, -1000, 2.0, 1.0)
    ItemChangeOpacity("cover_02", 0.0, 2.0, 1.0)
    DelayedExec(1.0, function() SoundPlay("sound/sphere.ogg") end, 113)
    ItemMove("circle_03", 0, -1000, 2.0, 1.5)
    ItemChangeOpacity("cover_03", 0.0, 2.0, 1.5)
    DelayedExec(1.5, function() SoundPlay("sound/sphere.ogg") end, 113)
    ItemMove("circle_04", 0, -1000, 2.0, 2.0)
    ItemChangeOpacity("cover_04", 0.0, 2.0, 2.0)
    DelayedExec(2.0, function() SoundPlay("sound/sphere_02.ogg") end, 113)
    ItemChangeOpacity("sphere_light", 1.0, 2.0, 2.0)
    
    SetState(CURRENT_SCREEN, "state", "finish")
    
    DelayedExec(5.0, function()
        
        SetState("screen_chapters_screen", "current_chapter", "4")
        clApplication:LoadLocation("Intro_03")
    end, 113)
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "13_lasers", "graphics/screens/13_lasers/location/13_lasers", 0, 0);
    self:CreateObj(OBJ_TYPE.TRIGGER, "floor", "graphics/screens/13_lasers/location/floor", 29, 856);
    self:CreateObj(OBJ_TYPE.TRIGGER, "ceiling", "graphics/screens/13_lasers/location/ceiling", 307, 0);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_right", "graphics/screens/13_lasers/location/wall_right", 1132, 0);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_left", "graphics/screens/13_lasers/location/wall_left", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "circle_04", "graphics/screens/13_lasers/location/circle_04", 567, 49);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "circle_03", "graphics/screens/13_lasers/location/circle_03", 635, 135);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "circle_01", "graphics/screens/13_lasers/location/circle_01", 749, 239);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "circle_02", "graphics/screens/13_lasers/location/circle_02", 696, 198);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cover_02", "graphics/screens/13_lasers/location/cover_02", 422, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cover_01", "graphics/screens/13_lasers/location/cover_01", 422, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cover_03", "graphics/screens/13_lasers/location/cover_03", 422, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cover_04", "graphics/screens/13_lasers/location/cover_04", 422, 0);

    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "sphere_light", "graphics/screens/13_lasers/location/sphere_light", 393, 0);
    ItemSetOpacity("sphere_light", 0.0)
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_13_part", "graphics/screens/13_lasers/location/crystal_13_part", 182, 951);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_09", "graphics/screens/13_lasers/location/emitter_09_dead", 152, 139);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_08", "graphics/screens/13_lasers/location/emitter_08_dead", 178, 555);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_07", "graphics/screens/13_lasers/location/emitter_07_dead", 341, 749);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_06", "graphics/screens/13_lasers/location/emitter_06_dead", 738, 1010);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_05", "graphics/screens/13_lasers/location/emitter_05_dead", 996, 916);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_04", "graphics/screens/13_lasers/location/emitter_04_dead", 1221, 588);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_03", "graphics/screens/13_lasers/location/emitter_03_dead", 1392, 643);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_02", "graphics/screens/13_lasers/location/emitter_02_dead", 1367, 200);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "emitter_01", "graphics/screens/13_lasers/location/emitter_01_dead", 1201, 229);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_15", "graphics/screens/13_lasers/location/mirror_16", 291, 221);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_14", "graphics/screens/13_lasers/location/mirror_14", 123, 392);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_13", "graphics/screens/13_lasers/location/mirror_13", 415, 391);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_12", "graphics/screens/13_lasers/location/mirror_12", 303, 681);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_11", "graphics/screens/13_lasers/location/mirror_11", 186, 916);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_10", "graphics/screens/13_lasers/location/mirror_10", 514, 888);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_9", "graphics/screens/13_lasers/location/mirror_09", 611, 1006);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_8", "graphics/screens/13_lasers/location/mirror_08", 881, 892);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_7", "graphics/screens/13_lasers/location/mirror_07", 1256, 1025);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_6", "graphics/screens/13_lasers/location/mirror_06", 1362, 844);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_5", "graphics/screens/13_lasers/location/mirror_05", 1288, 677);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_4", "graphics/screens/13_lasers/location/mirror_04", 1247, 380);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_3", "graphics/screens/13_lasers/location/mirror_03", 1444, 388);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_2", "graphics/screens/13_lasers/location/mirror_02", 1292, 198);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mirror_1", "graphics/screens/13_lasers/location/mirror_01", 1160, 64);
   
    --
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_09c", "graphics/screens/13_lasers/location/laser_09c", 204, 94);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_09b", "graphics/screens/13_lasers/location/laser_09b", 413, 94);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_09a", "graphics/screens/13_lasers/location/laser_09a", 810, 637);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_09", "graphics/screens/13_lasers/location/laser_09", 205, 217);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_07c", "graphics/screens/13_lasers/location/laser_07c", 356, 552);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_07b", "graphics/screens/13_lasers/location/laser_07b", 368, 244);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_07a", "graphics/screens/13_lasers/location/laser_07a", 368, 154);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_07", "graphics/screens/13_lasers/location/laser_07", 362, 155);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_06b", "graphics/screens/13_lasers/location/laser_06b", 411, 192);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_06a", "graphics/screens/13_lasers/location/laser_06a", 408, 184);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_06", "graphics/screens/13_lasers/location/laser_06", 773, 534);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_08", "graphics/screens/13_lasers/location/laser_08", 210, 583);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_08_04", "graphics/screens/13_lasers/location/laser_08-04", 879, 729);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_04_08", "graphics/screens/13_lasers/location/laser_04-08", 336, 491);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_04", "graphics/screens/13_lasers/location/laser_04", 336, 490);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_03", "graphics/screens/13_lasers/location/laser_03", 986, 678);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_02_03", "graphics/screens/13_lasers/location/laser_02-03", 205, 465);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_02", "graphics/screens/13_lasers/location/laser_02", 205, 261);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_05", "graphics/screens/13_lasers/location/laser_05", 463, 141);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_05_01", "graphics/screens/13_lasers/location/laser_05-01", 158, 141);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_01_05", "graphics/screens/13_lasers/location/laser_01-05", 158, 754);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "laser_01", "graphics/screens/13_lasers/location/laser_01", 468, 257);
    --self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "Text_13", "graphics/screens/13_lasers/location/Text_13", 452, 1130);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_right_01_insert", "graphics/screens/13_lasers/location/wall_right_01_insert", 1256, 721);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_right_02_insert", "graphics/screens/13_lasers/location/wall_right_02_insert", 1393, 526);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_right_03_insert", "graphics/screens/13_lasers/location/wall_right_03_insert", 1176, 628);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_right_04_insert", "graphics/screens/13_lasers/location/wall_right_04_insert", 1182, 545);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_right_05_insert", "graphics/screens/13_lasers/location/wall_right_05_insert", 1225, 148);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_left_04_insert", "graphics/screens/13_lasers/location/wall_left_04_insert", 364, 236);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_left_05_insert", "graphics/screens/13_lasers/location/wall_left_05_insert", 402, 176);
    self:CreateObj(OBJ_TYPE.TRIGGER, "floor_02_insert", "graphics/screens/13_lasers/location/floor_02_insert", 802, 898);
    self:CreateObj(OBJ_TYPE.TRIGGER, "ceiling_01_insert", "graphics/screens/13_lasers/location/ceiling_01_insert", 412, 100);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_left_03_insert", "graphics/screens/13_lasers/location/wall_left_03_insert", 329, 482);
    self:CreateObj(OBJ_TYPE.TRIGGER, "floor_03_insert", "graphics/screens/13_lasers/location/floor_03_insert", 871, 1067);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_left_02_insert", "graphics/screens/13_lasers/location/wall_left_02_insert", 199, 456);
    self:CreateObj(OBJ_TYPE.TRIGGER, "floor_04_insert", "graphics/screens/13_lasers/location/floor_04_insert", 976, 1065);
    self:CreateObj(OBJ_TYPE.TRIGGER, "ceiling_02_insert", "graphics/screens/13_lasers/location/ceiling_02_insert", 460, 147);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wall_left_01_insert", "graphics/screens/13_lasers/location/wall_left_01_insert", 150, 743);
    self:CreateObj(OBJ_TYPE.TRIGGER, "floor_01_insert", "graphics/screens/13_lasers/location/floor_01_insert", 461, 1061);
    ItemSetScale("ceiling_01_insert", 2.0)
    
    clScreenManager:add_screen("hud") 
    HUDScreen:SetMiniGameMode()
end