function OnSceneLoad_scorpion(screen)
    LoadData_scorpion(screen)
    
    local set_mouse_dependent_states = function(object, mouse_not_over, mouse_over, mouse_pressed)
        if not game_state.mouse_dependent_states then
            game_state.mouse_dependent_states = {}
        end
        
        game_state.mouse_dependent_states[object] = {}
        game_state.mouse_dependent_states[object].mouse_not_over = mouse_not_over
        game_state.mouse_dependent_states[object].mouse_over     = mouse_over
        game_state.mouse_dependent_states[object].mouse_pressed  = mouse_pressed
        
        play_field:IgnoreOnTestPoint( mouse_not_over )
        play_field:IgnoreOnTestPoint( mouse_over )
        play_field:IgnoreOnTestPoint( mouse_pressed )

        play_field:GetObject( mouse_not_over ):AttachTo(play_field:GetObject(object))
        play_field:GetObject( mouse_over     ):AttachTo(play_field:GetObject(object))
        play_field:GetObject( mouse_pressed  ):AttachTo(play_field:GetObject(object))
        
        play_field:GetObject( mouse_not_over ):SetXY(0, 0);
        play_field:GetObject( mouse_not_over ):SetZ(1);
        
        play_field:GetObject( mouse_over ):SetXY(0, 0);
        play_field:GetObject( mouse_over ):SetZ(1);
        
        play_field:GetObject( mouse_pressed ):SetXY(0, 0);
        play_field:GetObject( mouse_pressed ):SetZ(1);

        play_field:GetObject( mouse_over     ):SetVisible(false)
        play_field:GetObject( mouse_pressed  ):SetVisible(false)
    end
    
    set_mouse_dependent_states( 'reset_btn',
                                'reset_not_over',
                                'reset_over',
                                'reset_pressed')
    
    zoom_scorpion = CreateZoomZone( 'area_scorpion',
                                    'CloseZoneScorpion',
                                    'ZOOM_scorpion', 	    true,
                                    'scorpion_tail',        true,
                                    'scorpion_joint_1',     true,
                                    'scorpion_joint_2',     true,
                                    'scorpion_joint_3',     true,
                                    'scorpion_joint_4',     true,
                                    'scorpion_joint_5',     true,
                                    'area_circle_1',     true,
                                    'area_circle_2',     true,
                                    'area_circle_3',     true,
                                    'area_circle_4',     true,
                                    'area_circle_5',     true,
                                    'scorpion_gristle_1',   true,
                                    'scorpion_gristle_2',   true,
                                    'scorpion_gristle_3',   true,
                                    'scorpion_gristle_4', 	true,
                                    'scorpion_gristle_5', 	true,
                                    '1a',                   true,
                                    '1f',                   true,
                                    '2a',                   true,
                                    '2f',                   true,
                                    '3a',                   true,
                                    'Bottom',               true,
                                    'reset_btn',            true,
                                    'reset_not_over',       true,
                                    'reset_over',           true,
                                    'reset_pressed',        true,
                                    'area_scorpion_cover',  true);
    
    for i=1, 5 do
        screen:GetObject('area_circle_'..i):GetAnimation():SetColor('0x01FFFFFF');
    end
    
    if HasGameState('ActionCompleted', 'DupensHouseScorpionScatchShown') then
        zoom_scorpion.SetObjectVisible('area_scorpion_cover', false);
    end

	zoom_scorpion.on_open = function()
        mini_game_active = true;
        
        screen:GetObject('scorpion_joint_1'):SetOpacity(1);
        screen:GetObject('scorpion_joint_2'):SetOpacity(1);
        screen:GetObject('scorpion_joint_3'):SetOpacity(1);
        screen:GetObject('scorpion_joint_4'):SetOpacity(1);
        screen:GetObject('scorpion_joint_5'):SetOpacity(1);
        screen:GetObject('scorpion_tail'):SetOpacity(1);
        screen:GetObject('scorpion_gristle_2'):SetOpacity(1);
        screen:GetObject('scorpion_gristle_3'):SetOpacity(1);
        screen:GetObject('scorpion_gristle_4'):SetOpacity(1);
        screen:GetObject('scorpion_gristle_5'):SetOpacity(1);
        
        screen:GetObject('ZOOM_scorpion'):SetOpacity(0.4);
        screen:GetObject('1f'):SetOpacity(0.4);
        screen:GetObject('2f'):SetOpacity(0.4);
        screen:GetObject('Bottom'):SetOpacity(0.4);
    end
    
    zoom_scorpion.on_close = function()
        screen:GetObject('1a'):SetOpacity(0.4);
        screen:GetObject('2a'):SetOpacity(0.4);
        screen:GetObject('3a'):SetOpacity(0.4);

    end
    
    mini_game_state         = {}
    mini_game_state.screen  = screen;
    mini_game_active        = false;
    mini_game_completed     = false;
    
    screen:IgnoreOnTestPoint('scorpion_joint_1');
    screen:IgnoreOnTestPoint('scorpion_joint_2');
    screen:IgnoreOnTestPoint('scorpion_joint_3');
    screen:IgnoreOnTestPoint('scorpion_joint_4');
    screen:IgnoreOnTestPoint('scorpion_joint_5');
	screen:IgnoreOnTestPoint('scorpion_tail');
	screen:IgnoreOnTestPoint('scorpion_gristle_1');
	screen:IgnoreOnTestPoint('scorpion_gristle_2');
	screen:IgnoreOnTestPoint('scorpion_gristle_3');
	screen:IgnoreOnTestPoint('scorpion_gristle_4');
	screen:IgnoreOnTestPoint('scorpion_gristle_5');
    
	Objects_S = {}
	for i = 1, 5 do
		Objects_S[i]= {};
		Objects_S[i].Entity         = screen:GetObject('scorpion_gristle_'..i);
		Objects_S[i].Angle          = 1;
		Objects_S[i].Direction      = 0;
		Objects_S[i].StartAngle     = Objects_S[i].Entity:GetAngle();
		Objects_S[i].Target         = screen:GetObject('scorpion_joint_'..i);
		Objects_S[i].TargetClicked  = screen:GetObject('area_circle_'..i);
		
		game_state.custom_cursors['area_circle_'..i] = 'CursorActive'
		game_state.ignore_on_highlight['area_circle_'..i] = true;
	end
	
	Objects_S[6]= {};
	Objects_S[6].Entity = screen:GetObject('scorpion_tail');
	Objects_S[6].Angle = 1;
	Objects_S[6].Direction = 0;
	Objects_S[6].StartAngle = Objects_S[6].Entity:GetAngle();
	Objects_S[6].Target = nil;

	auxAttachInPlace(Objects_S[1].Target,        Objects_S[1].Entity, 2);
	auxAttachInPlace(Objects_S[1].TargetClicked, Objects_S[1].Entity, 3);
	auxAttachInPlace(Objects_S[2].Entity,        Objects_S[1].Target, -1);
	
	auxAttachInPlace(Objects_S[2].Target,        Objects_S[2].Entity, 2);
	auxAttachInPlace(Objects_S[2].TargetClicked, Objects_S[2].Entity, 3);
	auxAttachInPlace(Objects_S[3].Entity,        Objects_S[2].Target, -1);
	
	auxAttachInPlace(Objects_S[3].Target,        Objects_S[3].Entity, 2);
	auxAttachInPlace(Objects_S[3].TargetClicked, Objects_S[3].Entity, 3);
	auxAttachInPlace(Objects_S[4].Entity,        Objects_S[3].Target, -1);
	
	auxAttachInPlace(Objects_S[4].Target,        Objects_S[4].Entity, 2);
	auxAttachInPlace(Objects_S[4].TargetClicked, Objects_S[4].Entity, 3);
	auxAttachInPlace(Objects_S[5].Entity,        Objects_S[4].Target, -1);
	
	auxAttachInPlace(Objects_S[5].Target,        Objects_S[5].Entity, 2);
	auxAttachInPlace(Objects_S[5].TargetClicked, Objects_S[5].Entity, 3);
	auxAttachInPlace(Objects_S[6].Entity,        Objects_S[5].Target, -1);

	Objects_S[2].Angle = 0;
	Objects_S[2].Entity:SetAngle(Objects_S[2].StartAngle + M_PI / 4 * (Objects_S[2].Angle - 1));
	Objects_S[3].Angle = 0;
	Objects_S[3].Entity:SetAngle(Objects_S[3].StartAngle + M_PI / 4 * (Objects_S[3].Angle - 1));
	Objects_S[5].Angle = 0;
	Objects_S[5].Entity:SetAngle(Objects_S[5].StartAngle + M_PI / 4 * (Objects_S[5].Angle - 1));
	Objects_S[6].Angle = 2;
	Objects_S[6].Direction = 1;
	Objects_S[6].Entity:SetAngle(Objects_S[6].StartAngle + M_PI / 4 * (Objects_S[6].Angle - 1));
end

function ResetAngles()
	for i = 1, 5 do
		Objects_S[i].Direction = 0;
	end
		
	Objects_S[2].Angle = 0;
	Objects_S[2].Entity:Rotate(Objects_S[2].StartAngle + M_PI / 4 * (Objects_S[2].Angle - 1) - Objects_S[2].Entity:GetAngle(), 0.2);
	Objects_S[3].Angle = 0;
	Objects_S[3].Entity:Rotate(Objects_S[3].StartAngle + M_PI / 4 * (Objects_S[3].Angle - 1) - Objects_S[3].Entity:GetAngle(), 0.2);
	Objects_S[4].Angle = 1;
	Objects_S[4].Entity:Rotate(Objects_S[4].StartAngle - Objects_S[4].Entity:GetAngle(), 0.2);
	Objects_S[5].Angle = 0;
	Objects_S[5].Entity:Rotate(Objects_S[5].StartAngle + M_PI / 4 * (Objects_S[5].Angle - 1) - Objects_S[5].Entity:GetAngle(), 0.2);
	Objects_S[6].Angle = 2;
	Objects_S[6].Direction = 1;
	Objects_S[6].Entity:Rotate(Objects_S[6].StartAngle + M_PI / 4 * (Objects_S[6].Angle - 1) - Objects_S[6].Entity:GetAngle(), 0.2);
end

function auxAttachInPlace(object, parentObject, z)
	local scrX,scrY = object:GetScrX(), object:GetScrY();
	object:AttachTo(parentObject);
	object:SetScrXY(scrX, scrY);
	if(z ~= nil)then
		object:SetZ(z);
	end
end

function GetObjectByName_scorpion(object_name)
	for i = 1, 5 do
		if(Objects_S[i].TargetClicked:GetName() == object_name) then
			return Objects_S[i + 1];
		end
	end
	
	return nil;
end

function IsCompleted()
	for i = 1,6 do
		if(Objects_S[i].Angle ~= 1) then
			return false;
		end
	end
	
	return true;
end

function OnObjectMouseDown_scorpion(object)
    if game_state.mouse_dependent_states[object:GetName()] then
        local info = game_state.mouse_dependent_states[object:GetName()]
        play_field:GetObject(info.mouse_not_over):SetVisible(false)
        play_field:GetObject(info.mouse_over):SetVisible(false)
        play_field:GetObject(info.mouse_pressed):SetVisible(true)
    end
    
    local obj_name = object:GetName();
    
    if obj_name == 'area_scorpion_cover' then
        ShowMonolog('C_02_HINT_NO_SCORPION_SCATCH', 'C_02_HINT_NO_SCORPION_SCATCH');
    end
    
    if obj_name == 'ZOOM_scorpion' then
        ShowMonolog('C_02_SCORPION_HINT', 'C_02_SCORPION_HINT');
    end
    
	if( mini_game_active == true and mini_game_completed == false) then
	
		if (object:GetName() == 'reset_btn') then
		    PlaySound('02_ReversButton');
		    
            ResetAngles();
        end
		
		local Obj = GetObjectByName_scorpion(object:GetName());
		if(Obj ~= nil) then
		    PlaySound('02_ScorpionClick')
		    
			if(Obj.Direction == 0) then
				Obj.Angle = Obj.Angle + 1;
			else
				Obj.Angle = Obj.Angle - 1;
			end
			
			if(Obj.Angle == 0 and Obj.Direction == 1) then
				Obj.Direction = 0;
			end
			if(Obj.Angle == 2 and Obj.Direction == 0) then
				Obj.Direction = 1;
			end
			
			Obj.Entity:SetAngle(Obj.StartAngle + M_PI / 4 * (Obj.Angle - 1));
			
			if(IsCompleted()) then
				mini_game_completed = true;
				DragObject = nil;
				play_field:GetObject('1a'):Rotate(M_PI, 1.0);
				play_field:GetObject('2a'):Rotate(M_PI, 1.0);
				play_field:GetObject('3a'):Rotate(M_PI, 1.0);
				
				PlaySound('02_ScorpionOpen')
				
				if HasGameState('MiniGameCompleted', '02_Scorpion') == false then
					AddGameState('MiniGameCompleted', '02_Scorpion')
				end
		
				TimerDoString('close_zoom_scorpion()', 1.0, play_field:GetTimer());
			end
		end
	end
end

function OnObjectMouseEnter_scorpion(object)
    if game_state.mouse_dependent_states[object:GetName()] then
        local info = game_state.mouse_dependent_states[object:GetName()]
        play_field:GetObject(info.mouse_not_over):SetVisible(false)
        play_field:GetObject(info.mouse_over):SetVisible(true)
        play_field:GetObject(info.mouse_pressed):SetVisible(false)
    end
end

function OnObjectMouseLeave_scorpion(object)
    if game_state.mouse_dependent_states[object:GetName()] then
        local info = game_state.mouse_dependent_states[object:GetName()]
        play_field:GetObject(info.mouse_not_over):SetVisible(true)
        play_field:GetObject(info.mouse_over):SetVisible(false)
        play_field:GetObject(info.mouse_pressed):SetVisible(false)
    end
end

function OnObjectMouseUp_scorpion(object)
    if not object then
        return;
    end
    
    if game_state.mouse_dependent_states[object:GetName()] then
        local info = game_state.mouse_dependent_states[object:GetName()]
        play_field:GetObject(info.mouse_not_over):SetVisible(false)
        play_field:GetObject(info.mouse_over):SetVisible(true)
        play_field:GetObject(info.mouse_pressed):SetVisible(false)
    end
end

function close_zoom_scorpion()
    
	if(zoom_scorpion ~= nil) then
        zoom_scorpion.SetVisible(false);
		zoom_scorpion.Disable();
		--play_field:GetObject('area_scorpion'):SetVisible(false);
        --play_field:GetObject('area_chest'   ):SetVisible(true);
        --play_field:GetObject('chest_top'    ):SetOpacity(1.);
        --play_field:GetObject('chest_corner' ):SetOpacity(1.);
        --game_state.chest.setIndex(2);
        game_state.need_open_chest = true;
	end
end
--function LoadData_scorpion(screen)
--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData_scorpion(screen)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/ZOOM_scorpion.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ZOOM_scorpion',anim,512,384,199,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_tail.png',0,0,70,50,1,0)
	anim:SetHotSpot(51,7)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_tail',anim,592,358,207,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_joint.png',0,0,46,45,1,0)
	anim:SetHotSpot(23,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_joint_1',anim,502,353,205,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_joint.png',0,0,46,45,1,0)
	anim:SetHotSpot(23,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_joint_2',anim,504,316,206,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_joint.png',0,0,46,45,1,0)
	anim:SetHotSpot(23,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_joint_3',anim,544,312,207,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_joint.png',0,0,46,45,1,0)
	anim:SetHotSpot(23,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_joint_4',anim,584,315,208,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_joint.png',0,0,46,45,1,0)
	anim:SetHotSpot(23,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_joint_5',anim,590,352,209,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_gristle.png',0,0,49,58,1,0)
	anim:SetHotSpot(24,51)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_gristle_1',anim,502,389,202,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_gristle.png',0,0,49,58,1,0)
	anim:SetHotSpot(24,51)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_gristle_2',anim,500,349,202,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_gristle_2.png',0,0,58,49,1,0)
	anim:SetHotSpot(5,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_gristle_3',anim,504,311,204,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_gristle_2.png',0,0,58,49,1,0)
	anim:SetHotSpot(5,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_gristle_4',anim,544,312,205,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/scorpion_gristle_3.png',0,0,49,58,1,0)
	anim:SetHotSpot(26,2)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scorpion_gristle_5',anim,585,318,206,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_circle_1',anim,502,355,210,0,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_circle_2',anim,506,317,210,0,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_circle_3',anim,543,313,210,0,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_circle_4',anim,582,317,210,0,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_circle_5',anim,588,354,210,0,0.25,0.25)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/1a.png',0,0,97,103,1,0)
	anim:SetHotSpot(46,53)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('1a',anim,345,288,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/1f.png',0,0,157,208,1,0)
	anim:SetHotSpot(78,104)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('1f',anim,338,294,201,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/2a.png',0,0,130,132,1,0)
	anim:SetHotSpot(62,72)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('2a',anim,664,292,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/2f.png',0,0,157,194,1,0)
	anim:SetHotSpot(78,97)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('2f',anim,670,301,201,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/3a.png',0,0,97,97,1,0)
	anim:SetHotSpot(51,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('3a',anim,502,565,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/Bottom.png',0,0,227,141,1,0)
	anim:SetHotSpot(113,70)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Bottom',anim,501,521,201,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/Reset_btn.png',0,0,56,67,1,0)
	anim:SetHotSpot(28,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('reset_btn',anim,265,565,220,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/Reset_btn.png',0,0,56,67,1,0)
	anim:SetHotSpot(28,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('reset_not_over',anim,265,565,220,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/Reset_btn.png',0,67,56,67,1,0)
	anim:SetHotSpot(28,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('reset_over',anim,265,565,220,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/02_scorpion/Reset_btn.png',0,134,56,67,1,0)
	anim:SetHotSpot(28,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('reset_pressed',anim,265,565,220,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_scorpion_cover',anim,512,384,230,0,80,60)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
