dofile('data/Scripts/Minigames/minigameScreen.lua')
------------------------------------------------------------------------------
function OnSceneLoad()
	play_field = miniGamePlayField;
    LoadData();
	play_field = nil;
	
	miniGamePlayField:EnableRightMouseButtonProcessing(true)
	
	OBJECTS_AMOUNT = 36
	STEAMS_AMOUNT = 12
	PIXELS = 84.0
	    
    miniGameState = {};
   	miniGameState.delayPeriod = 90.0;
   	miniGameState.timeElapsed = 0.0;
	miniGameState.steamActivationPeriod = 0.0;
   	miniGameState.delayPeriodPassed = false;
	miniGameState.completed = false;
	
	miniGamePlayField:IgnoreOnTestPoint('Background');
	miniGamePlayField:IgnoreOnTestPoint('Main_steam_');
		
	Pipes = {}
	prev_marker = nil
	global_marker = nil
	local hot_x, hot_y, sc_x, sc_y
	-- If color 0xFFFFFF00 then type is 'line' and color must be set to default
	for i = 1, OBJECTS_AMOUNT do
	    Pipes[i] = miniGamePlayField:GetObject("Pipe_"..i)
	    if Pipes[i]:GetAnimation():GetColorStr() == '0xFFFFFF00' then
	        Pipes[i].Type = 'line'
	        Pipes[i]:GetAnimation():SetColor('0xFFFFFFFF')
	    else
	        Pipes[i].Type = 'corner'
	    end
	    if i == 1 then
	        Pipes[i].Direction = 0
	    else
            Pipes[i].Direction = math.random(3)
	        Pipes[i]:SetAngle(Pipes[i].Direction * M_PI_OVER_2)
	    end
	    Pipes[i].Marker = 1
	    hot_x = Pipes[i]:GetAnimation():GetHotX()
        hot_y = Pipes[i]:GetAnimation():GetHotY()
        sc_x = Pipes[i]:GetX()
        sc_y = Pipes[i]:GetY()
        Pipes[i].x = sc_x - hot_x
        Pipes[i].y = sc_y - hot_y
        Pipes[i].x_2 = Pipes[i].x + PIXELS
        Pipes[i].y_2 = Pipes[i].y + PIXELS
	end
	
	miniGameState.steams = {}
	for i = 1, STEAMS_AMOUNT do
	    miniGameState.steams[i] = CreateSteam(0.0, 0.0, miniGamePlayField:GetObject('act_zone'..i), false)
	    miniGamePlayField:IgnoreOnTestPoint('act_zone'..i)
	end
	
	MainSteam = CreateSteam(0.0, 0.0, miniGamePlayField:GetObject('Main_steam'), false, 1.6)
	MainSteam.Object = miniGamePlayField:GetObject('Main_steam')
	MainSteam.Direction = 0
		
	function MainSteam.Fire(enable)
	    if enable == true then
	        MainSteam:SetGeneration(true)
	    else
	        MainSteam:SetGeneration(false)
	    end
	end
	
    function MainSteam.Set(x, y, angle)
        MainSteam.Object:SetXY(x, y)
	    MainSteam.Object:SetZ(99.0)
	    MainSteam.Object:SetAngle(angle + M_PI_OVER_2 / 3.0)
    	MainSteam:SetZ(0.0)
	end
	
	IsLevelComplete()
	DirectMainSteam()
			
	TimerDoString('OnShowHelp()', 0.5, miniGamePlayField:GetTimer())
end

function OnSceneFree()
    FreeData()
end

-------------------------------------------------------------
function CreateSteam(x, y, parentObject, enableParticleGeneration, scale)
    if enableParticleGeneration == nil then
        enableParticleGeneration = false
    end    
    if scale == nil then
        scale = 1.0
    end    
    
	local steamPS = CreateParticleSystemEntity('data/ParticleSystem/Steam.psi', 'SmokeParticle');
	steamPS:SetAngle(0.0);
	steamPS:AttachTo(parentObject);
	steamPS:SetXY(x, y);	
	steamPS:SetZ(200.0);
	steamPS:SetAngle(0.0);
	steamPS:SetScale(scale);
	steamPS:SetGeneration(enableParticleGeneration);
	steamPS:AffectedByParentAngleAndScale(true);
	
	return steamPS;
end

function EnableSteam(steamIndex, state)
    assert(miniGameState.steams ~= nil and table.getn(miniGameState.steams) >= steamIndex)
    miniGameState.steams[steamIndex]:SetGeneration(state)
end

function CreateArrowAnim(object)
	local duration = 0.80;

	Effector = CreateAnimationEffector();
	Effector:AttachTo(object);
	Effector:SetMode(_ANIM_LOOP);

	Effector:SetKey(_TRACK_A, 0.0, 0.0);
	Effector:SetKey(_TRACK_A, duration *1.0/4.0, -0.1);
	Effector:SetKey(_TRACK_A, duration *2.0/4.0, 1.1);
	Effector:SetKey(_TRACK_A, duration *3.0/4.0, -0.0);
	Effector:SetKey(_TRACK_A, duration *4.0/4.0, 1.7);
	Effector:SetKey(_TRACK_A, duration *5.0/4.0, 0.2);
	Effector:SetKey(_TRACK_A, duration *6.0/4.0, 1.5);
	Effector:SetKey(_TRACK_A, duration *7.0/4.0, -0.1);
	Effector:SetKey(_TRACK_A, duration *8.0/4.0, 0.00);
	
	Effector:Play();
end

-----------------------------------------------------------
function MarkPipes()
    for i = 1, OBJECTS_AMOUNT do
        Pipes[i].Marker = 1
    end
    Pipes[1].Marker = 2
    -- Find pipe with marker == 2 and process it
    local ret
    while FindMarker() do
        local x, y = Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()
        Pipes[global_marker].Marker = 3
        ret = false
        
        ret = CheckCell(x - PIXELS, y, Pipes[global_marker], 'left')
        if not ret then ret = CheckCell(x, y + PIXELS, Pipes[global_marker], 'down') end
        if not ret then ret = CheckCell(x, y - PIXELS, Pipes[global_marker], 'up') end
        if not ret then ret = CheckCell(x + PIXELS, y, Pipes[global_marker], 'right') end
    end
end

function FindMarker()
    for i = 1, OBJECTS_AMOUNT do
        if Pipes[i].Marker == 2 then
            global_marker = i
            return true
        end
    end
    return false
end

-- Mega functions with to many if()
function CheckCell(x, y, object, side, ignore_marker)
    ignore_marker = ignore_marker or false
    for i = 1, OBJECTS_AMOUNT do
        if x > Pipes[i].x and x < Pipes[i].x_2 and y > Pipes[i].y and y < Pipes[i].y_2 then
            if Pipes[i].Marker == 1 or ignore_marker then
                -----------------------------------------------------------------------------
                if object.Type == 'line' then
                    if side == 'up' then
                        if object.Direction == 1 or object.Direction == 3 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 1 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                                                               
                    elseif side == 'right' then
                        if object.Direction == 0 or object.Direction == 2 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 2 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 1 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                        
                    elseif side == 'down' then
                        if object.Direction == 1 or object.Direction == 3 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 1 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 1 or Pipes[i].Direction == 2 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                        
                    elseif side == 'left' then
                        if object.Direction == 0 or object.Direction == 2 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 2 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 2 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                    end
                --------------------------------------------------------------------------------------    
                else -- Type == 'corner'
                    if side == 'up' then
                        if object.Direction == 1 or object.Direction == 2 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 1 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
 
                    elseif side == 'right' then
                        if object.Direction == 2 or object.Direction == 3 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 2 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 1 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                        
                    elseif side == 'down' then
                        if object.Direction == 0 or object.Direction == 3 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 1 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 1 or Pipes[i].Direction == 2 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                    
                    elseif side == 'left' then
                        if object.Direction == 0 or object.Direction == 1 then
                            if Pipes[i].Type == 'line' then
                                if Pipes[i].Direction == 0 or Pipes[i].Direction == 2 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            else -- Type == 'corner'
                                if Pipes[i].Direction == 2 or Pipes[i].Direction == 3 then
                                    if not ignore_marker then Pipes[i].Marker = 2 end
                                    return true
                                end
                            end
                        end
                    end
                    
                end
            end
            
            return false
        end
    end
    
    return false
end
-----------------------------------------------------------
function OnUpdate(dt)
	miniGameState.timeElapsed = miniGameState.timeElapsed + dt;
	auxUpdateProgressBar(miniGameState.timeElapsed > miniGameState.delayPeriod and 1.0 or miniGameState.timeElapsed / miniGameState.delayPeriod);
	
    if(miniGameState.completed == false and
       miniGameState.timeElapsed > miniGameState.delayPeriod and  miniGameState.delayPeriodPassed == false)  then
        miniGameState.delayPeriodPassed = true;
        auxShowButton(false);
    end
    
    if miniGameState.completed then
		local STEAM_ACTIVATION_PERIOD = 0.01;
		miniGameState.steamActivationPeriod = miniGameState.steamActivationPeriod + dt;
		if (miniGameState.steams ~= nil and table.getn(miniGameState.steams) > 0 and
			miniGameState.steamActivationPeriod > STEAM_ACTIVATION_PERIOD) then
			miniGameState.steamActivationPeriod = miniGameState.steamActivationPeriod - STEAM_ACTIVATION_PERIOD;
			
			local rand = math.random(2);
			for i = 1, rand do
				local steamRandomIndex = math.random(table.getn(miniGameState.steams));
				miniGamePlayField:GetObject('act_zone'..steamRandomIndex):SetAngle(math.random(M_PI * 2))
				if(math.random(1, 2) == 1)then
					miniGameState.steams[steamRandomIndex]:SetZ(96);
				else
					miniGameState.steams[steamRandomIndex]:SetZ(105);
				end
				local steamActivity = 5.0 * math.random();
				EnableSteam(steamRandomIndex, true);
				TimerDoString('EnableSteam('..steamRandomIndex..', false)', steamActivity, miniGamePlayField:GetTimer());
			end
		end
	end
end

function OnShowHelp()
	miniGamePlayField:GetLevelScreen():ShowDialog(500, 300, GetTextString('MINIGAME_PIPES_HELP'), GetTextString('MINIGAME_HELP_DIALOG_TITLE'));
end

function GetObjectByName(obj_name)
    for i = 1, OBJECTS_AMOUNT do
        if Pipes[i]:GetName() == obj_name then
            return Pipes[i]
        end
    end
    return nil
end

function DirectMainSteam()
    if global_marker then --and global_marker~=prev_marker then
	    local direct
		if Pipes[global_marker].Type == 'line' then
		    if Pipes[global_marker].Direction == 0 or Pipes[global_marker].Direction == 2 then
		        if CheckCell(Pipes[global_marker]:GetX()-PIXELS, Pipes[global_marker]:GetY(), Pipes[global_marker], 'left', true) then direct = 1  
                else direct = 3 end
		    else -- 1 or 3
	    	    if CheckCell(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()-PIXELS, Pipes[global_marker], 'up', true) then direct = 2
                else direct = 0 end
		    end
		    MainSteam.Set(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY(), direct * M_PI_OVER_2 + M_PI_OVER_2)
		        
	    else
		    if Pipes[global_marker].Direction == 0 then
		        if CheckCell(Pipes[global_marker]:GetX()-PIXELS, Pipes[global_marker]:GetY(), Pipes[global_marker], 'left', true) then direct = 2    
                else direct = 3 end
		    elseif Pipes[global_marker].Direction == 1 then
		        if CheckCell(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()-PIXELS, Pipes[global_marker], 'up', true) then direct = 3
                else direct = 0 end
		    elseif Pipes[global_marker].Direction == 2 then
		        if CheckCell(Pipes[global_marker]:GetX()+PIXELS, Pipes[global_marker]:GetY(), Pipes[global_marker], 'right', true) then direct = 0
                else direct = 1 end
		    else
		        if CheckCell(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()+PIXELS, Pipes[global_marker], 'down', true) then direct = 1    
                else direct = 2 end
		    end
		    MainSteam.Set(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY(), direct * M_PI_OVER_2 + M_PI_OVER_2)
        end
		    
		if MainSteam.Direction ~= direct then
		    MainSteam.Fire(false)
		    TimerDoString('MainSteam.Fire(true)', 1.0, miniGamePlayField:GetTimer())
	    end
		MainSteam.Direction = direct
    end   
end

function OnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pipe = GetObjectByName(obj_name)
	if pipe then
	    local dir = pipe.Direction
	    dir = dir + 1
	    if dir > 3 then 
	        dir = 0
	    end
	    pipe.Direction = dir
		pipe:SetAngle(dir * M_PI_OVER_2)
		
		PlaySound('L06S01')
		
		prev_marker = global_marker
		
		if IsLevelComplete() then
			FinishMinigame()
		end
		
		DirectMainSteam()
	end
end

function IsLevelComplete()
    MarkPipes()
    
    if Pipes[OBJECTS_AMOUNT].Marker == 3 and Pipes[OBJECTS_AMOUNT].Direction == 1 then 
        return true
    end
	
	return false
end

function FinishMinigame()
    for i =1, OBJECTS_AMOUNT do
		miniGamePlayField:IgnoreOnTestPoint(Pipes[i]:GetName());
	end
	CreateArrowAnim(miniGamePlayField:GetObject('par04'));
	miniGameState.completed = true;
	miniGamePlayField:EnableRightMouseButtonProcessing(false);
	auxShowButton(true);
end

function OnObjectMouseUp(object)
end

function OnObjectRightMouseDown(object)
    local obj_name = object:GetName()
    local pipe = GetObjectByName(obj_name)
	if pipe then
	    local dir = pipe.Direction
	    dir = dir - 1
	    if dir < 0 then 
	        dir = 3
	    end
	    pipe.Direction = dir
		pipe:SetAngle(dir * M_PI_OVER_2)
		
		PlaySound('L06S01')
		
		prev_marker = global_marker
		
		if IsLevelComplete() then
			FinishMinigame()
		end
		
		if global_marker then --and global_marker~=prev_marker then
		    local direct
		    if Pipes[global_marker].Type == 'line' then
		        if Pipes[global_marker].Direction == 0 or Pipes[global_marker].Direction == 2 then
		            if CheckCell(Pipes[global_marker]:GetX()-PIXELS, Pipes[global_marker]:GetY(), Pipes[global_marker], 'left', true) then direct = 1  
                    else direct = 3 end
		        else -- 1 or 3
	    	        if CheckCell(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()-PIXELS, Pipes[global_marker], 'up', true) then direct = 2
                    else direct = 0 end
		        end
		        MainSteam.Set(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY(), direct * M_PI_OVER_2 + M_PI_OVER_2)
		        
		    else
		        if Pipes[global_marker].Direction == 0 then
		            if CheckCell(Pipes[global_marker]:GetX()-PIXELS, Pipes[global_marker]:GetY(), Pipes[global_marker], 'left', true) then direct = 2    
                    else direct = 3 end
		        elseif Pipes[global_marker].Direction == 1 then
		            if CheckCell(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()-PIXELS, Pipes[global_marker], 'up', true) then direct = 3
                    else direct = 0 end
		        elseif Pipes[global_marker].Direction == 2 then
		            if CheckCell(Pipes[global_marker]:GetX()+PIXELS, Pipes[global_marker]:GetY(), Pipes[global_marker], 'right', true) then direct = 0
                    else direct = 1 end
		        else
		            if CheckCell(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY()+PIXELS, Pipes[global_marker], 'down', true) then direct = 1    
                    else direct = 2 end
		        end
		        MainSteam.Set(Pipes[global_marker]:GetX(), Pipes[global_marker]:GetY(), direct * M_PI_OVER_2 + M_PI_OVER_2)
		    end
		    
		    if MainSteam.Direction ~= direct then
		        MainSteam.Fire(false)
		        TimerDoString('MainSteam.Fire(true)', 1.0, miniGamePlayField:GetTimer())
		    end
		    MainSteam.Direction = direct
		end
	end
end

function OnObjectRightMouseUp(object)
end

function OnMouseMove(previousPos, currentPos)
end

function OnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData()
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone1',anim,681,529,105,270,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone2',anim,432,532,105,270,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone3',anim,263,294,105,270,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone4',anim,428,209,105,90,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone5',anim,389,414,105,-10,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone6',anim,629,161,105,0,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone7',anim,793,160,105,120,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone8',anim,386,334,105,2291,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone9',anim,595,368,105,132,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone10',anim,302,158,105,20,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone11',anim,760,365,105,270,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/par04.png',0,0,34,12,1,0)
	anim:SetHotSpot(22,6)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('par04',anim,905,569,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/par05.png',0,0,54,56,1,0)
	anim:SetHotSpot(27,27)
	anim:SetBlendMode(2)
	anim:SetColor('0x60FFFFFF')
	play_field:CreateObject('par05',anim,906,569,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_2',anim,762,568,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_3',anim,680,568,100,180,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_4',anim,681,488,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_5',anim,761,488,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_6',anim,841,485,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_7',anim,840,403,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_8',anim,839,323,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_9',anim,759,324,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_10',anim,758,406,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_11',anim,678,408,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_12',anim,597,408,100,180,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_13',anim,596,328,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_14',anim,675,326,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_15',anim,675,244,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_16',anim,755,244,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_17',anim,835,241,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_18',anim,834,161,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_19',anim,752,162,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_20',anim,670,163,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_21',anim,590,164,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_22',anim,590,246,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_23',anim,510,248,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_24',anim,428,248,100,180,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_25',anim,425,169,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_26',anim,263,172,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_27',anim,263,254,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_28',anim,265,334,100,180,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_29',anim,343,170,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_30',anim,427,334,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_31',anim,428,413,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_32',anim,346,335,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_33',anim,350,416,100,270,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_34',anim,350,496,100,180,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_35',anim,430,495,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_corner.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Pipe_36',anim,431,574,100,90,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Background.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,512)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Background',anim,511,511,95,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('act_zone12',anim,174,217,105,270,0.2,0.3)
	local anim = CreateAnimation('data/Texture/Scenes/Common/actZoneC.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('Main_steam',anim,96,102,105,0,0.2,0.2)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Datchik.png',0,0,142,104,1,0)
	anim:SetHotSpot(71,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('BigPipe',anim,875,566,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/Pipe/Pipe_line.png',0,0,84,84,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFF00')
	play_field:CreateObject('Pipe_1',anim,846,569,100,0,1,1)
end

function FreeData()
end
-- CLEAR_ON_SAVE_END
