local zone_picture

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/21_Make_Up_Room_Main.lua', 'quest')

	LinkScene('area_corridor', 'CursorDoorRightUp', 'data/Scenes/19_Corridor_Main.lua', false)
	LinkScene('area_ho1', 'CursorGlass', 'data/Scenes/21_Make_Up_Room_HO1.lua', true)
	LinkScene('area_ho2', 'CursorGlass', 'data/Scenes/21_Make_Up_Room_HO2.lua', true)
	
	LoadSound('21_Spider', 'data/Sound/21_Make_Up_Room/21_Spider.ogg');
	
	play_field:GetObject('area_monolog'):SetMaxOpacity(0.001)
	zone_picture = CreateZoomZone('area_zoom_photo',
                                  'CloseZonePicture',
                                  'master_girl', true,
								  'area_monolog', true)
	--RegisterActiveObject('area_monolog', 'C_21_PICTURE')
	RegisterActiveObject('area_monolog',
						 function()
							ShowMonolog('C_21_PICTURE', 'C_21_PICTURE')
							game_state.ignore_on_highlight['area_zoom_photo'] = true
							game_state.ignore_on_highlight['area_monolog'] = true
						 end,
						 function()
							game_state.ignore_on_highlight['area_zoom_photo'] = true
							game_state.ignore_on_highlight['area_monolog'] = true
						 end,
						 true,
						 'CursorGlass')

	RegisterMonologObject('area_puppet_hook', 'C_21_PUPPET_HOOK', true)
	RegisterMonologObject('area_woman_hat', 'C_21_WOMAN_HAT', true)

	if HasGameState('AllSceneTaskObjectsFound', 'data/Scenes/21_Make_Up_Room_HO1.lua') and
       HasGameState('AllSceneTaskObjectsFound', 'data/Scenes/21_Make_Up_Room_HO2.lua')
    then
        
        if not HasGameState('SpiderManVanished', '21')
        then
            if (play_field.toolWindowInfo)
            then
                play_field.toolWindowInfo.finalizeCallback = function()
                    TimerDoString("PlaySpiderManFleeingAnimation();", 
                                  1, play_field:GetTimer());
                    MakeSoundEntity('21_Spider'):Play(false);
                end
            else
                TimerDoString("PlaySpiderManFleeingAnimation();" ..
                              "MakeSoundEntity('21_Spider'):Play(false);", 
                              1, play_field:GetTimer());
            end
            
            AddGameState('SpiderManVanished', '21');
            
        end
        
    end
    
end

function PlaySpiderManFleeingAnimation()

    createCompositionSpiderFleeing = function()
    
        local compositionSpiderFleeing = CreateCompositionSequence();
        local compositionDuration = 3.16666666666667;
        compositionSpiderFleeing:SetDuration(compositionDuration);
    
    
        -- Layer Layer_closes_over
        local element = CreateCompositionElement("data/Texture/Scenes/21_Make_Up_Room/Zone_Main/Animations/layer.png");
        element:SetName("Layer_closes_over");
        compositionSpiderFleeing:AddElement(element);
        element:SetHotSpot(192, 78);
        element:SetParentElement(compositionSpiderFleeing);
        element:SetXY(731, 527);
    
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 15);
    
    
        effector:Play();
    
    
        -- Layer Spider_man_fleeing
        local element = CreateCompositionElement("data/Texture/Scenes/21_Make_Up_Room/Zone_Main/Animations/sh.png");
        element:SetName("Spider_man_fleeing");
        compositionSpiderFleeing:AddElement(element);
        element:SetHotSpot(260.5, 12.5);
        element:SetParentElement(compositionSpiderFleeing);
        
            anim = element:GetTexture();
			anim:SetSpeed(24);
			anim:SetFrames(9);
			anim:SetFrame(0);
			anim:SetTextureRect(0, 0, 301, 199);
			anim:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
			anim:Play();
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 2.25);
    
        effector:SetKey(_TRACK_X, 0, 908);
        effector:SetKey(_TRACK_Y, 0, 465);
        effector:SetKey(_TRACK_X, 0.91666666666667, 822.846236762954);
        effector:SetKey(_TRACK_Y, 0.91666666666667, 551.296101664144);
        effector:SetKey(_TRACK_X, 1.58333333333333, 757);
        effector:SetKey(_TRACK_Y, 1.58333333333333, 480);
        effector:SetKey(_TRACK_X, 2.08333333333333, 727);
        effector:SetKey(_TRACK_Y, 2.08333333333333, 464);
        effector:SetKey(_TRACK_SX, 0, 1.64);
        effector:SetKey(_TRACK_SY, 0, 1.64);
        effector:SetKey(_TRACK_SX, 0.91666666666667, 0.65421052631579);
        effector:SetKey(_TRACK_SY, 0.91666666666667, 0.65421052631579);
        effector:SetKey(_TRACK_SX, 1.58333333333333, 1.2);
        effector:SetKey(_TRACK_SY, 1.58333333333333, 1.2);
        effector:SetKey(_TRACK_SX, 1.83333333333333, 1.595);
        effector:SetKey(_TRACK_SY, 1.83333333333333, 1.595);
        effector:SetKey(_TRACK_SX, 2.08333333333333, 0.73);
        effector:SetKey(_TRACK_SY, 2.08333333333333, 0.73);
        effector:SetKey(_TRACK_A, 0, 0);
        effector:SetKey(_TRACK_A, 1.58333333333333, 0.383972435);
        effector:SetKey(_TRACK_A, 2.08333333333333, 0.5410520675);
        effector:SetKey(_TRACK_O, 0, 0.5);
        effector:SetKey(_TRACK_O, 0.91666666666667, 1);
        effector:SetKey(_TRACK_O, 2.25, 0.01);
    
        effector:Play();
    
    
        compositionSpiderFleeing:Play();
    
        return compositionSpiderFleeing;
    end

    local compos = createCompositionSpiderFleeing();
    compos:AttachTo(play_field);
    compos:SetZ(48);

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)
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/21_Make_Up_Room/Zone_Main/Layers/BG_MakeUp_Room.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_MakeUp_Room',anim,512,384,45,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/21_Make_Up_Room/Zone_Main/Layers/Beams.png',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(0)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Beams',anim,507,386,50,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_ho1',anim,218,333,100,0,25,25)
	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_ho2',anim,508,425,100,0,30,20)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(8,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_zoom_photo',anim,669,239,100,0,20,20)
	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_corridor',anim,742,384,100,0,20,30)
	local anim = CreateAnimation('data/Texture/Scenes/21_Make_Up_Room/Zone_Main/Zoom_Photo/master_girl.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('master_girl',anim,512,384,150,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('0x00FFFFFF')
	screen:CreateObject('area_monolog',anim,513,383,151,352,70,50)
	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_puppet_hook',anim,133,564,100,0,12,4)
	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_woman_hat',anim,880,53,100,-45,7,13)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
