class 'l_02_Mountain_path' (PlayField)

local paralax_full_shift_time = 1
local paralax_planes_max_shift 	= {}
if IS_PARALAX_MODE then
	paralax_planes_max_shift 		= {90, 40, 10, 0}
else
	paralax_planes_max_shift 		= {0, 0, 0, 0}
end

function l_02_Mountain_path:__init(game_scene, name, path)
	PlayField.__init(self, game_scene, name, path)
	
	self:linkScene('area_link_01',   'CursorDown',    '01_Boat_crash_site')
	self:linkScene('area_link_03',   'CursorUp',    '03_Panorama')
	
	self:entityHide('area_apply_loaded_harpoon', 'area_apply_wheel_block', 'area_link_03')
	
	self:entityHide('rope_clew', 'rope', 'rope_part2', 'wheel_block_2','bg_eagle_fly')
	
	self:addNote('Note_02_Molinari')	

	do  -- find clock -----------------------------------------------------   
        if not self:isObjectClicked('area_click_clock_2') then
        	self:getEntityNamed('area_click_clock_2'):hide()
            self.timer:add( function() 
                                self:fadeGhostClock('clock_2', 'cover_clock_02', 'area_click_clock_2')
                            end, 35)   
        end

        function on_click(event)
            self:entityHide('clock_2')
            self:entityHide('area_click_clock_2')
            if not event.save then  
                self:entityFadeHide('cover_clock_02') 
            else 
                self:entityHide('cover_clock_02') 
            end
        end
        self:registerFindClockObject('area_click_clock_2', 'fly_clock_2', 'clock_2', on_click)
    end

    self:registerBBT('bbt_02_vortex_1', 'BBT_02_VORTEX')
    self:registerBBT('bbt_02_vortex_2', 'BBT_02_VORTEX')
	-- fist start ---------------------------------------------------------
    if self:isFirstVisited() then
    	
    end

    if IsToolFound('01_strong_rope_net') and not isSceneVisited('03_Panorama') then
       	local video = createVideo({video = 'fury_idle', order = 1, x = 555, y = 227, isLooped = true, isAlpha = true, parent = 'anchor_plane_3'})  
       	video:setColor(Colorf(0.6, 0.6, 0.6, 0.8))
    	video:play()
    	self:getEntityNamed('area_click_fury'):show()
    	self:registerBBT('area_click_fury', 'BBT_02_CLICK_FURY')
    end

    if IsToolFound('01_bulb_lamp') then
       self:entityHide('bone')
    end

    if IsToolFound('01_bulb_lamp') and not HasGameState('04_Dead_body_Burned') then
    	SetGameState('04_Dead_body_Burned', 'true')

    	dofile('Data/Scripts/Scenes/02_Mountain_path/Animations/02_Mountain_path_Bg_dead_body_fire_Animation.lua')
		local bg_deadbodyfire = createCompositionbgf()
		bg_deadbodyfire:attachTo(self:getEntityNamed('anchor_plane_2'))
	    bg_deadbodyfire:setXY(-171,  0)
		bg_deadbodyfire:setOrder(30)
		
		self.timer:add(function()
    	local video = createVideo({video = 'dead_body_burn', order = 60, x = 810, y = 392, isLooped = false, isAlpha = false, parent = 'anchor_plane_2'})
    	video:setBlend(RenderedObject.EBlendModeColorAdd)
    	video:play()
			   		
		 end, 2)


    end
    -----------------------------------------------------------------------
       -- find photo ---------------------------------------------------------------
    do
        local function on_take_photo(event)    
           -- self:entityShow('')     
        end

        self:registerFindFlyPhoto('area_find_photo', '02_Molinari', on_take_photo)
    end
    -- find photo ---------------------------------------------------------------

	-- planes help --------------------------------------------------------
	if IS_PARALAX_MODE then
	    self.anchor_planes = {}
	    for i = 1,#paralax_planes_max_shift do
	        self.anchor_planes[i] = self:getEntityNamed('anchor_plane_'..i)
	    end
	    self:getMainEntity().onUpdate:add(function(obj,dt)
	            self:onUpdate(dt)
	        end)

	    self.prevMousePos = {}
	end
    ----------------------------------------------------------------------------
	    
	if not HasGameState('02_Mountain_path_Bridge_ruined') then
	    AddUniqueGameState('02_Mountain_path_Bridge_ruined', 'true')

	    local function on_end_cutscene()
	        
	        self:showBlackBar('BBT_02_MOLINARY_RAN_AWAY')
	        
	        local function on_end()
	            self.dog_action:ChangeOpacity(1, 0, 0.2)
	            self:getEntityNamed('Layer_eagle_action'):ChangeOpacity(1, 0, 0.2)
	            self:getEntityNamed('composition_layer_3'):getElementByName('eagle'):setOpacity(1)
           	self.mouseBlocker:pop()
	        end

	        addGameTask('04')
	    
	    	self.dog_action	= createVideo({video = 'dog_action', order = 60, x = 580, y = 560, isLooped = false, isAlpha = true, parent = 'anchor_plane_2', sound = '02_ze_eagle_action'})
	    	self.dog_action.onFinish:add( on_end )
	    	self:getEntityNamed('Layer_eagle_action'):show()
	    	self:getEntityNamed('Layer_eagle_action'):play()
        	self.mouseBlocker:push()

	        self:getEntityNamed('composition_layer_3'):getElementByName('eagle'):setOpacity(0)

        	 self.dog_action:play()
        	
	    	self:playSound('dog_action')
		end 

        local video = createVideo({video = 'molinari_running', scale = 1.51 , order = 1000, sound = '02_molinari_running'})
        self:startCutScene(video, on_end_cutscene)
     --    local subtitles = Subtitles(self:getPanel():getControlsPanel())
	    -- subtitles:pushReplic('SUB_02_MOLINARI', 0.5, 3, true)
	    -- subtitles:play()
	else
		addGameTask('04')
	end
	
	self.zoom_bush = self:createZoomZone('Bush')

    self.zoom_dead_body = self:createZoomZone('Dead_body')
	
    self.zoom_eagle = self:createZoomZone('Eagle')
    
    self:registerBBT('area_bbt_abyss', 'BBT_02_ABYSS')

   	local function on_apply_loaded_harpoon(e)
	    self:entityHide(e.target)
	    self:entityHide('area_bbt_abyss')
	    self:entityShow('area_apply_wheel_block')
	    if not e.save then

   		     self:getEntityNamed('harpoon'):show() 
   		     self:getEntityNamed('harpoon'):stop() 
   		     self:getEntityNamed('harpoon'):play()
   		     self:playSound('02_harpoon')
   		     
   		     self.timer:add( function()
					                 self:getEntityNamed('harpoon'):hide() 
					         end, 1)

	        self:entityShow('rope', 'rope_part2')
	        self:getEntityNamed('rope_clew'):ChangeOpacity(1,0,0.5,1)
	        self:getEntityNamed('rope'):ChangeOpacity(0,1,0.5,1)
	        self:getEntityNamed('rope_part2'):ChangeOpacity(0,1,0.5,1)
	    else
	        self:entityHide('rope_clew')
	        self:entityShow('rope', 'rope_part2')
	    end
	end
	self:registerToolApplyInfo('02_loaded_harpoon', 'area_apply_loaded_harpoon', on_apply_loaded_harpoon, 'BBT_02_NEED_LOADED_HARPOON')
	
	local function on_apply_wheel_block(e)
	    self:entityHide(e.target)
	    self:entityShow('area_link_03')
	    
	    self:entityShow('wheel_block_2')
	    
	    if not e.save then
	        local video = createVideo({video = 'riding', scale = 1.51, order = 1000, sound = '02_riding'})
            self:startCutScene(video, function() 
            							  startLevel('l_03_Panorama') 
            						  end)     

	    elseif not isSceneVisited('03_Panorama') then
	        self.timer:add( function()
				                startLevel('l_03_Panorama')
				            end, 0)
	    end
	end
	self:registerToolApplyInfo('02_wheel_block', 'area_apply_wheel_block', on_apply_wheel_block, 'BBT_02_NEED_WHELL_BLOCK')
end

--------------------------------------------------------------------------------
function l_02_Mountain_path:onUpdate(dt)
	if IS_PARALAX_MODE then
	    if self.active_zones:GetTop() or self.hidden_zoom_zones.zones:GetTop() or self.paralax_blocked then
	        return
	    end
	    local mouse_pos = GetCursorEntity():getScrPosition()

	    if self.prevMousePos.x ~= mouse_pos.x or self.prevMousePos.x ~= mouse_pos.y then
	    
	        self.prevMousePos = mouse_pos
	        local plane_shift_proportion = -(mouse_pos.x-WSCR_W/2)/WSCR_W

	        
	        	self:changeScale(plane_shift_proportion)
	        

	        for i =1,#paralax_planes_max_shift do
	            local target_plane_x = plane_shift_proportion * paralax_planes_max_shift[i]
	            local current_plane_x = self.anchor_planes[i]:getX()
	            local target_time = math.abs(current_plane_x - target_plane_x)/(2*paralax_planes_max_shift[i])
	            local new_plane_x = dt<target_time and current_plane_x + ((target_plane_x - current_plane_x)*dt/target_time) or target_plane_x
	            self.anchor_planes[i]:setX(new_plane_x)
	        end
	   end
	end
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function l_02_Mountain_path:changeScale(dscale)
	local obj 		= self:getEntityNamed('rope_part2')
	local obj_scale = 1.0

	obj:setScaleX(obj_scale  + dscale/4)
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function l_02_Mountain_path:CreateLoaderTable()
	local objects =
	{
		{ name = 'bg',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/bg.jpg',  width = 1366,  height = 768,  },
		{ name = 'area_bbt_abyss',  entityType = 'SpriteEntity',  x = 564,  y = 338,  order = 99,  scaleX = 2.5,  scaleY = 1.8,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Bush',  entityType = 'SpriteEntity',  x = 347,  y = 419,  order = 100,  scale = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_link_03',  entityType = 'SpriteEntity',  x = 561,  y = 323,  order = 100,  scaleX = 2.5,  scaleY = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Dead_body',  entityType = 'SpriteEntity',  x = 815,  y = 444,  order = 100,  angle = -15,  scaleX = 3.2,  scaleY = 2.2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Common/Area_Round.png',  width = 128,  height = 128,  },
		{ name = 'area_link_01',  entityType = 'SpriteEntity',  x = 512,  y = 718,  order = 100,  scaleX = 11,  scaleY = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Eagle',  entityType = 'SpriteEntity',  x = 861,  y = 187,  order = 100,  scaleX = 1.5,  scaleY = 2.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_apply_wheel_block',  entityType = 'SpriteEntity',  x = 691,  y = 303,  order = 110,  angle = 5,  scaleX = 3.5,  scaleY = 1.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_apply_loaded_harpoon',  entityType = 'SpriteEntity',  x = 634,  y = 347,  order = 110,  angle = 5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 300,  height = 170,  },
		{ name = 'anchor_plane_1',  entityType = 'SpriteEntity',  x = 0,  y = 0,  order = 10,  color = {r = 1, g = 1, b = 1, a = 0.0235294},  editingLocked = false,  treeItemIsExpanded = true,  width = 2,  height = 2,  },
		{ name = 'tree',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_1',  x = 3,  y = 384,  order = 30,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/tree.png',  width = 440,  height = 768,  },
		{ name = '02_Mountain_path_Bg_layer_4_Animation',  entityType = 'CompositionContainer',  parentName = 'anchor_plane_1',  x = -171,  y = 0,  order = 25,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/02_Mountain_path/Animations/02_Mountain_path_Bg_layer_4_Animation.lua',  },
		{ name = 'compositionBG',  entityType = 'CompositionSequence',  parentName = '02_Mountain_path_Bg_layer_4_Animation',  x = 5,  y = -1,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  isCyclic = true,  speed = 1,  },
		{ name = 'anchor_plane_2',  entityType = 'SpriteEntity',  x = 0,  y = 0,  order = 8,  color = {r = 1, g = 1, b = 1, a = 0.0235294},  editingLocked = false,  treeItemIsExpanded = true,  width = 2,  height = 2,  },
		{ name = 'bone',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 771,  y = 437,  order = 9,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/bone.png',  width = 269,  height = 231,  },
		{ name = 'harpoon',  entityType = 'VideoEntity',  parentName = 'anchor_plane_2',  x = 673,  y = 467,  order = 30,  isVisible = false,  isRespondable = false,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Video/Scenes/02_Mountain_path/harpoon.webm',  hasAlpha = true,  isLooped = false,  fps = 24,  },
		{ name = 'spear',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 771,  y = 377,  order = 20,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/spear.png',  width = 94,  height = 48,  },
		{ name = 'sabre',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 918,  y = 480,  order = 20,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/sabre.png',  width = 128,  height = 22,  },
		{ name = 'rope_clew',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 776,  y = 353,  order = 15,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/rope_clew.png',  width = 142,  height = 180,  },
		{ name = 'front_bg',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 513,  y = 483,  order = 2,  isRespondable = false,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/front_bg.png',  width = 1462,  height = 569,  },
		{ name = '02_Mountain_path_Bg_layer_3_Animation',  entityType = 'CompositionContainer',  parentName = 'front_bg',  x = -684,  y = -483,  order = 25,  isRespondable = false,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/02_Mountain_path/Animations/02_Mountain_path_Bg_layer_3_Animation.lua',  },
		{ name = 'composition_layer_3',  entityType = 'CompositionSequence',  parentName = '02_Mountain_path_Bg_layer_3_Animation',  x = -1,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'number_key',  entityType = 'SpriteEntity',  parentName = '02_Mountain_path_Bg_layer_3_Animation',  x = 440,  y = 469,  order = 4,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/number_key.png',  width = 44,  height = 32,  },
		{ name = 'Layer_eagle_action',  entityType = 'VideoEntity',  parentName = '02_Mountain_path_Bg_layer_3_Animation',  x = 1039,  y = 160,  order = 0,  isVisible = false,  scale = 0.35,  editingLocked = false,  treeItemIsExpanded = false,  path = 'Data/Video/Scenes/02_Mountain_path/Layer_eagle_action.webm',  hotSpot = {x = 288, y = 256},  hasAlpha = true,  isLooped = false,  fps = 24,  },
		{ name = 'rope',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 699,  y = 315,  order = 15,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/rope.png',  width = 298,  height = 130,  },
		{ name = 'wheel_block_2',  entityType = 'SpriteEntity',  parentName = 'rope',  x = 66,  y = 35,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/wheel_block_2.png',  width = 50,  height = 80,  },
		{ name = 'wheel_block_1',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_2',  x = 316,  y = 548,  order = 24,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/wheel_block_1.png',  width = 116,  height = 76,  },
		{ name = 'clock_2',  entityType = 'SpriteEntity',  x = 168,  y = 507,  order = 25,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/clock_02_loc.png',  width = 42,  height = 72,  },
		{ name = 'cover_clock_02',  entityType = 'SpriteEntity',  x = 160,  y = 508,  order = 30,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/cover_clock_02.png',  width = 74,  height = 68,  },
		{ name = 'fly_clock_2',  entityType = 'SpriteEntity',  x = 203,  y = 508,  order = 50,  isVisible = false,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/fly_clock_2.png',  width = 250,  height = 250,  },
		{ name = 'anchor_plane_3',  entityType = 'SpriteEntity',  x = 0,  y = 0,  order = 6,  color = {r = 1, g = 1, b = 1, a = 0.0235294},  editingLocked = false,  treeItemIsExpanded = true,  width = 2,  height = 2,  },
		{ name = 'rope_part2',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_3',  x = 551.5,  y = 309,  order = 4,  editingLocked = false,  treeItemIsExpanded = false,  hotSpot = {x = 0, y = 61},  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/rope_part2.png',  width = 111,  height = 122,  },
		{ name = 'middle_bg',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_3',  x = 204,  y = 361,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/middle_bg.png',  width = 842,  height = 554,  },
		{ name = 'bg_eagle_fly',  entityType = 'VideoEntity',  parentName = 'anchor_plane_3',  x = 692,  y = 114,  order = 0,  isRespondable = false,  editingLocked = false,  treeItemIsExpanded = false,  path = 'Data/Video/Scenes/02_Mountain_path/bg_eagle_fly.webm',  hotSpot = {x = 376, y = 104},  hasAlpha = true,  isLooped = true,  fps = 24,  },
		{ name = 'area_click_fury',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_3',  x = 547,  y = 216,  order = 10,  isVisible = false,  isRespondable = false,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 100,  },
		{ name = 'anchor_plane_4',  entityType = 'SpriteEntity',  x = 0,  y = 0,  order = 4,  color = {r = 1, g = 1, b = 1, a = 0.0235294},  editingLocked = false,  treeItemIsExpanded = true,  width = 2,  height = 2,  },
		{ name = 'back_bg',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_4',  x = 907,  y = 298,  order = 15,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/back_bg.png',  width = 674,  height = 326,  },
		{ name = 'sky',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_4',  x = 512,  y = 169,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/sky.png',  width = 1366,  height = 338,  },
		{ name = 'storm',  entityType = 'SpriteEntity',  parentName = 'anchor_plane_4',  x = 774,  y = 251,  order = 5,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/02_Mountain_path/Layers/storm.png',  width = 124,  height = 214,  },
		{ name = '02_Mountain_path_Bg_layer_1_Animation',  entityType = 'CompositionContainer',  parentName = 'anchor_plane_4',  x = -171,  y = 0,  order = 10,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/02_Mountain_path/Animations/02_Mountain_path_Bg_layer_1_Animation.lua',  },
		{ name = 'composition_layer_1',  entityType = 'CompositionSequence',  parentName = '02_Mountain_path_Bg_layer_1_Animation',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'area_click_clock_2',  entityType = 'SpriteEntity',  x = 145,  y = 499,  order = 150,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 100,  },
		{ name = 'area_find_photo',  entityType = 'SpriteEntity',  x = 386,  y = 182,  order = 200,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'bbt_02_vortex_1',  entityType = 'SpriteEntity',  x = 589,  y = 104,  order = 100,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 400,  height = 200,  },
		{ name = 'bbt_02_vortex_2',  entityType = 'SpriteEntity',  x = 1092,  y = 110,  order = 100,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 300,  height = 200,  },
	}
	return objects
end
