function add_fibrillation_effector_light(obj, delay)
	local duration = 7.0

	eff= CreateAnimationEffector()
	eff:AttachTo(obj)
	eff:SetMode(_ANIM_LOOP)

    local dopacity = -0.

	eff:SetKey(_TRACK_O, 0.0 + delay, 1.0 + dopacity)
	eff:SetKey(_TRACK_O, duration * 1.0/4.0 + delay, 0.75 + dopacity)
	eff:SetKey(_TRACK_O, duration * 2.0/4.0 + delay, 1.0 + dopacity)
	eff:SetKey(_TRACK_O, duration * 3.0/4.0 + delay, 0.59 + dopacity)
	eff:SetKey(_TRACK_O, duration * 4.0/4.0 + delay, 1.0 + dopacity)
	eff:Play()
end

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/16_Theatre_Dead_End_Main.lua', 'quest')

	RegisterQuestObjects('area_ho', 'bush1', 'area_ladder')

    local condition = function()
        return HasGameState('ToolApplied', '15_ladder')
    end
    local on_condition_fail = function()
		if not HasGameState('ToolApplied', '15_ladder') then
			ShowMonolog('16_NoLadder', 'C_16_NO_LADDER')
		end
    end
    LinkScene('area_ho', 'CursorGlass', 'data/Scenes/16_Theatre_Dead_End_HO.lua', true, condition, on_condition_fail)

    LinkScene('area_back', 'CursorDoorDown', 'data/Scenes/13_Theatre_Fountain_Main.lua', false)
	
	if HasGameState('ToolFound', '13_float') and HasGameState('ToolFound', '21_scissors') then
		game_state.ignore_on_highlight['area_back'] = true
	end

    if not HasGameState('ToolApplied', '15_ladder') then
        local on_ladder_click = function()
            ShowMonolog('16_Wall', 'C_16_WALL')
        end
        RegisterActiveObject('area_ladder', on_ladder_click, nil, true, 'CursorGlass')
    end

	play_field:GetObject('bush2'):SetOpacity(0.)
	play_field:GetObject('Layer_door'):SetOpacity(0.)

	play_field:GetObject('area_door_for_tool'):Hide()
	local register_door_area = function()
		play_field:GetObject('area_door_for_tool'):Show()
		local on_apply = function()
			play_field:GetObject('Layer_door'):ChangeOpacity(0., 1., 1.4)
			LinkScene('Layer_door', 'CursorDoorRight', 'data/Scenes/26_Backyard_Main.lua', false)
			play_field:GetObject('area_door_for_tool'):Hide()
			MakeSoundEntity('15_Door_open'):Play(false);
		end
		local on_load_when_tool_applied = function()
			play_field:GetObject('Layer_door'):SetOpacity(1.)
			LinkScene('Layer_door', 'CursorDoorRight', 'data/Scenes/26_Backyard_Main.lua', false)
			play_field:GetObject('area_door_for_tool'):Hide()
		end
		RegisterToolApplyInfo('13_float', 'area_door_for_tool', nil, nil, on_apply, on_load_when_tool_applied)
		RegisterMonologObject('area_door_for_tool', 'C_16_CLOSED_DOOR')
	end
	
	local on_scissors_apply = function()
		play_field:GetObject('bush1'):ChangeOpacity(1., 0., 1.4)
		play_field:GetObject('bush2'):ChangeOpacity(0., 1., 1.4)
		register_door_area();
		
		MakeSoundEntity("CuttingLianas"):Play(false);
	end
	local on_load_when_scissors_applied = function()
		play_field:GetObject('bush1'):SetOpacity(0.)
		play_field:GetObject('bush2'):SetOpacity(1.)
		register_door_area()
	end
	RegisterToolApplyInfo('21_scissors', 'bush1', nil, nil, on_scissors_apply, on_load_when_scissors_applied)
	RegisterMonologObject('bush1', 'C_16_BUSH')

	-----
	local on_ladder_apply = function()
		play_field:GetObject('StairWay'):ChangeOpacity(0., 1., 0.3)
		UnregisterActiveObject('area_ladder')
		game_state.ignore_on_highlight['area_ladder'] = true
		MakeSoundEntity('16_Ladder'):Play(false);
	end
	local on_load_when_ladder_applied = function()
		game_state.ignore_on_highlight['area_ladder'] = true
	end
    RegisterToolApplyInfo('15_ladder', 'area_ladder', nil, nil, on_ladder_apply, on_load_when_ladder_applied)

	if not HasGameState('ToolApplied', '15_ladder') then
		play_field:GetObject('StairWay'):SetOpacity(0.)
	end
	-----

    add_fibrillation_effector_light(play_field:GetObject('Layer_Light'), 0.0)

	RegisterMonologObject('area_bear', 'C_16_BEAR', true)
	
	LoadSound("CuttingLianas", "data/Sound/16_Theatre_DeadEnd/Cutting_lianas.ogg");
	LoadSound('16_Ladder', 'data/Sound/16_Theatre_DeadEnd/Ladder.ogg');
	LoadSound('15_Door_open', 'data/Sound/16_Theatre_DeadEnd/Door_open.ogg');
end

function OnSceneFree(screen)
    DefaultOnSceneFree()
    FreeData(screen)
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
end

function OnAllItemsFound()
    DefaultOnAllItemsFound()
end

function OnLose()
    DefaultOnLose()
end

function OnExit()
    DefaultOnExit()
end

function OnClose()
    DefaultOnClose()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

function OnObjectMouseDown(object)
    local is_wrong_click = not DefaultOnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pf = play_field

    DefaultOnObjectMouseDownProcessed(is_wrong_click);
end

function OnObjectMouseUp(object)
    DefaultOnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)
end

function OnToolFound(tool)
    DefaultOnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
    DefaultOnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
    DefaultOnSetTool(tool)
end

function LevelLoaded(level)
    local anim = level:CreateAnimation('data/Texture/Scenes/Common/Clouds.png');
	anim:SetPosXY(512, 0);
	anim:SetOpacity(0.6);
	anim:SetScaleXY(1, 1);
	anim:SetPosZ(43);
	
	local effector = CreateTextureEffector();
	effector:AttachToAnimation(anim);
	effector:SetSpeed(-16);
	effector:Play();
end

function OnSceneDestroy(playfield)
    DefaultOnSceneDestroy(playfield)
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/BG_DeadEnd.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_DeadEnd',anim,512,386,40,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_ho',anim,235,119,121,0,30,30)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('area_door',anim,810,527,100,0,40,40)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_back',anim,457,714,125,0,100,15)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/Layer_Top.png',0,0,1024,224,1,0)
	anim:SetHotSpot(512,112)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Top',anim,512,113,45,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/Layer_Light.png',0,0,227,228,1,0)
	anim:SetHotSpot(113,114)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Light',anim,764,354,70,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/bush1.png',0,0,216,374,1,0)
	anim:SetHotSpot(125,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bush1',anim,823,452,65,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/bush2.png',0,0,192,97,1,0)
	anim:SetHotSpot(96,48)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bush2',anim,632,664,70,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(5,3)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_ladder',anim,270,332,120,355,30,80)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/Layer_door.jpg',0,0,234,372,1,0)
	anim:SetHotSpot(117,186)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_door',anim,832,580,50,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/16_Theatre_Dead_End/Zone_Main/Layers/StairWay.PNG',0,0,148,508,1,0)
	anim:SetHotSpot(74,254)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('StairWay',anim,266,447,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Sky.JPG',0,0,1024,220,1,0)
	anim:SetHotSpot(512,0)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Sky',anim,512,0,42,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_bear',anim,161,516,125,0,10,10)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_door_for_tool',anim,815,545,100,0,25,40)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
