dofile('data/Scripts/Minigames/minigameScreen.lua');
-- miniGameScreen

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

function OnSceneLoad()
	play_field = miniGamePlayField;
    LoadData();
	play_field = nil;
	
	Consecution = {}
	for i = 1, 3 do
		Consecution[i] = {}
	end
	
	--немного странная конструкция, трехмерный массив получился, 
	--но вроде в данном случае довольно читабильно получилось и не режит глаза
	Consecution[1][1] = {5, 2, 3}
	Consecution[1][2] = {1, 3, 2}
	Consecution[1][3] = {4, 1, 5}
	
	Consecution[2][1] = {1, 5, 4, 2, 3}
	Consecution[2][2] = {2, 1, 3, 5, 4}
	Consecution[2][3] = {4, 5, 1, 3, 2}
	
	Consecution[3][1] = {1, 5, 2, 1, 3, 2, 5}
	Consecution[3][2] = {4, 1, 3, 1, 4, 2, 5}
	Consecution[3][3] = {2, 5, 1, 3, 4, 2, 1}
	
	cur_razklad = math.random(3);
	cur_consecution = 1;
	cur_down = 1;
	
   	miniGameState = {};
   	miniGameState.delayPeriod = 90.0;
   	miniGameState.timeElapsed = 0.0;
   	miniGameState.delayPeriodPassed = false;
   	miniGameState.completed = false;
   	miniGameState.locked = true;
   	
	auxLoadDataAndPlayIntro();  
	
	math.randomseed(os.clock());
	math.random();  -- dummy function call to futher proper usage
	
	Elements = {}
	for i = 1,3 do
		Elements[i] = miniGamePlayField:GetObject('Znaki_0'..i)
		Elements[i]:SetOpacity(0.0);
	end
	
	music_volume = GetMusicVolume(GetCurrentMusicName());
	SetMusicVolume(GetCurrentMusicName(), 0.1);
	
	TimerDoString('OnShowHelp()', 0.5, miniGamePlayField:GetTimer());	
	TimerDoString('PlayConsecution(1)', 1.8, miniGamePlayField:GetTimer());
	
	cur_text = '';
end

function auxNilText()
	cur_text = '';
end

function auxShowText()
	miniGamePlayField:GetLevelScreen():ShowTip(cur_text);
end

function auxHideText()
	miniGamePlayField:GetLevelScreen():HideTip();
end

function OnSceneFree()
	SetMusicVolume(GetCurrentMusicName(), music_volume);
    FreeData()
end

function PlayConsecution(Index)
	auxPlayDrum(Consecution[cur_consecution][cur_razklad][Index]);
	PlaySound('L01S0'..Consecution[cur_consecution][cur_razklad][Index]);
	
	if(Consecution[cur_consecution][cur_razklad][Index + 1] ~= nil) then
		TimerDoString('PlayConsecution('..(Index + 1)..')', 1.0, miniGamePlayField:GetTimer());
	else
		TimerDoString('miniGameState.locked = false', 0.4, miniGamePlayField:GetTimer());
	end
end

--// AE animations auxiliary functions - - - - - - - - - - - - - - - - - - - -
--//
function auxCreateCompositionElement(composition, resourceName, elementName)
    assert(miniGameState ~= nil and composition ~=nil and 
		   resourceName ~= nil and elementName ~= nil and
		   resourceName ~= '' and elementName ~= '');
    
    if (miniGameState.elements == nil) then
        miniGameState.elements = {};
		miniGameState.composition = composition;
    end
    
    if (miniGameState.elements[elementName] ~= nil) then
        return miniGameState.elements[elementName];
    else
	    local element = CreateCompositionElement(resourceName);
	    element:SetName(elementName);
	    composition:AddElement(element);

        --// set additive alpha blending mode for 'glow' objects without alpha chanel (*.jpg)
        if (string.find(resourceName, 'glow_') ~= nil) then
            element:GetTexture():SetBlendMode(0);
        end

        miniGameState.elements[elementName] = element;
        return element;
    end
end

--//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--//
function auxPlayElements(...)
	assert(miniGameState ~= nil and miniGameState.elements ~= nil and 
		   miniGameState.composition ~= nil and miniGameState.timeOffset ~= nil);

    local elementsToPlay = {};
    for i,v in ipairs({...}) do
        elementsToPlay[v] = true;
    end
    
	for elementName,element in pairs(miniGameState.elements) do
	    if (elementsToPlay[elementName] == true) then
    	    local effector = element:GetEffector();
		    effector:Play();
		end
	end
end

--//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--//
function auxLoadDataAndPlayIntro()
	-- replace 							--//	1. ' -> '
	screen = miniGamePlayField;  		--//	2. +
	local element;                      --//    3. +
	local effector;				 		--//	4. +
	local zOffset = 2;                  --//    5. +
	
	miniGameState.timeOffset = 0.0;			--//	7. +
	local timeOffset = miniGameState.timeOffset;

    local composition = CreateCompositionSequence();
    composition:SetConsiderParentOpacity(false);
    local compositionDuration = 2000.7;
    composition:SetDuration(compositionDuration);
    composition:AttachTo(screen);
    composition:SetZ(zOffset);
    composition:SetDestroysOnEnd(false);    --// +
    
    
    -- Layer Layer_1
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_red.jpg', 'Layer_1');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_1', 'Layer_25');
    element:SetXY(278.5, 180.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.13333333333333, 1);
    effector:SetKey(_TRACK_O, 0.3, 0);
    
    -- Layer Layer_2
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_mal.jpg', 'Layer_2');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_2', 'Layer_25');
    element:SetXY(369.5, 26.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.13333333333333, 1);
    effector:SetKey(_TRACK_O, 0.3, 0);
    
    -- Layer Layer_3
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_yel.jpg', 'Layer_3');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_3', 'Layer_25');
    element:SetXY(119.5, 127.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.13333333333333, 1);
    effector:SetKey(_TRACK_O, 0.3, 0);
    
    -- Layer Layer_4
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_blue.jpg', 'Layer_4');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_4', 'Layer_25');
    element:SetXY(432.5, 131.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.13333333333333, 1);
    effector:SetKey(_TRACK_O, 0.3, 0);
    
    -- Layer Layer_5
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_green.jpg', 'Layer_5');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_5', 'Layer_25');
    element:SetXY(184.5, 12.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.13333333333333, 1);
    effector:SetKey(_TRACK_O, 0.3, 0);
    
    -- Layer Layer_6
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_blue.jpg', 'Layer_6');
    element:SetHotSpot(48, 48);
    element:SetParentElement(composition);
    element:SetXY(541, 109);
    
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.33333333333333, 1.2);
    effector:SetKey(_TRACK_SY, 0.33333333333333, 1.2);
    effector:SetKey(_TRACK_SX, 0.63333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.63333333333333, 1);
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.33333333333333, 1);
    effector:SetKey(_TRACK_O, 0.63333333333333, 0);
    effector:SetKey(_TRACK_O, 0.93333333333333, 0.6);
    effector:SetKey(_TRACK_O, 1.5, 0.3);
    effector:SetKey(_TRACK_O, 1.9, 0.6);
    effector:SetKey(_TRACK_O, 2.3, 0);
    
    -- Layer Layer_7
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_green.jpg', 'Layer_7');
    element:SetHotSpot(48, 48);
    element:SetParentElement(composition);
    element:SetXY(517, 166);
    
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.33333333333333, 1.2);
    effector:SetKey(_TRACK_SY, 0.33333333333333, 1.2);
    effector:SetKey(_TRACK_SX, 0.63333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.63333333333333, 1);
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.33333333333333, 1);
    effector:SetKey(_TRACK_O, 0.63333333333333, 0);
    effector:SetKey(_TRACK_O, 0.93333333333333, 0.6);
    effector:SetKey(_TRACK_O, 1.5, 0.3);
    effector:SetKey(_TRACK_O, 1.9, 0.6);
    effector:SetKey(_TRACK_O, 2.3, 0);
    
    -- Layer Layer_8
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_yel.jpg', 'Layer_8');
    element:SetHotSpot(48, 48);
    element:SetParentElement(composition);
    element:SetXY(510, 56);
    
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_SX, 0, 1);
    effector:SetKey(_TRACK_SY, 0, 1);
    effector:SetKey(_TRACK_SX, 0.3, 1.2);
    effector:SetKey(_TRACK_SY, 0.3, 1.2);
    effector:SetKey(_TRACK_SX, 0.6, 1);
    effector:SetKey(_TRACK_SY, 0.6, 1);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.3, 1);
    effector:SetKey(_TRACK_O, 0.6, 0);
    effector:SetKey(_TRACK_O, 0.9, 0.6);
    effector:SetKey(_TRACK_O, 1.46666666666667, 0.3);
    effector:SetKey(_TRACK_O, 1.86666666666667, 0.6);
    effector:SetKey(_TRACK_O, 2.26666666666667, 0);
    
    -- Layer Layer_9
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_02.png', 'Layer_9');
    element:SetHotSpot(66, 68.5);
    composition:RegisterParentInfo('Layer_9', 'Layer_25');
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 437.5);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 151.5);
    effector:SetKey(_TRACK_X, 0.1, 437.5);
    effector:SetKey(_TRACK_Y, 0.1, 162.5);
    effector:SetKey(_TRACK_X, 0.16666666666667, 437.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 151.5);
    effector:SetKey(_TRACK_X, 0.23333333333333, 437.5);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 154.5);
    effector:SetKey(_TRACK_X, 0.3, 437.5);
    effector:SetKey(_TRACK_Y, 0.3, 151.5);
    effector:SetKey(_TRACK_X, 0.36666666666667, 437.5);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 153.5);
    effector:SetKey(_TRACK_X, 0.43333333333333, 437.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 151.5);
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.1, 1.1);
    effector:SetKey(_TRACK_SY, 0.1, 1);
    effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
    effector:SetKey(_TRACK_SY, 0.16666666666667, 1);
    
    -- Layer Layer_10
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_03.png', 'Layer_10');
    element:SetHotSpot(58.5, 60);
    composition:RegisterParentInfo('Layer_10', 'Layer_25');
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 369.5);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 43.5);
    effector:SetKey(_TRACK_X, 0.1, 369.5);
    effector:SetKey(_TRACK_Y, 0.1, 54.5);
    effector:SetKey(_TRACK_X, 0.16666666666667, 369.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 43.5);
    effector:SetKey(_TRACK_X, 0.23333333333333, 369.5);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 46.5);
    effector:SetKey(_TRACK_X, 0.3, 369.5);
    effector:SetKey(_TRACK_Y, 0.3, 43.5);
    effector:SetKey(_TRACK_X, 0.36666666666667, 369.5);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 45.5);
    effector:SetKey(_TRACK_X, 0.43333333333333, 369.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 43.5);
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.1, 1.1);
    effector:SetKey(_TRACK_SY, 0.1, 1);
    effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
    effector:SetKey(_TRACK_SY, 0.16666666666667, 1);
    
    -- Layer Layer_11
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_04.png', 'Layer_11');
    element:SetHotSpot(58.5, 60);
    composition:RegisterParentInfo('Layer_11', 'Layer_25');
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 185.5);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 39.5);
    effector:SetKey(_TRACK_X, 0.1, 185.5);
    effector:SetKey(_TRACK_Y, 0.1, 50.5);
    effector:SetKey(_TRACK_X, 0.16666666666667, 185.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 39.5);
    effector:SetKey(_TRACK_X, 0.23333333333333, 185.5);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 42.5);
    effector:SetKey(_TRACK_X, 0.3, 185.5);
    effector:SetKey(_TRACK_Y, 0.3, 39.5);
    effector:SetKey(_TRACK_X, 0.36666666666667, 185.5);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 41.5);
    effector:SetKey(_TRACK_X, 0.43333333333333, 185.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 39.5);
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.1, 1.1);
    effector:SetKey(_TRACK_SY, 0.1, 1);
    effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
    effector:SetKey(_TRACK_SY, 0.16666666666667, 1);
    
    -- Layer Layer_12
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_05.png', 'Layer_12');
    element:SetHotSpot(66, 68.5);
    composition:RegisterParentInfo('Layer_12', 'Layer_25');
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 117.5);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 148.5);
    effector:SetKey(_TRACK_X, 0.1, 117.5);
    effector:SetKey(_TRACK_Y, 0.1, 159.5);
    effector:SetKey(_TRACK_X, 0.16666666666667, 117.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 148.5);
    effector:SetKey(_TRACK_X, 0.23333333333333, 117.5);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 151.5);
    effector:SetKey(_TRACK_X, 0.3, 117.5);
    effector:SetKey(_TRACK_Y, 0.3, 148.5);
    effector:SetKey(_TRACK_X, 0.36666666666667, 117.5);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 150.5);
    effector:SetKey(_TRACK_X, 0.43333333333333, 117.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 148.5);
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.1, 1.1);
    effector:SetKey(_TRACK_SY, 0.1, 1);
    effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
    effector:SetKey(_TRACK_SY, 0.16666666666667, 1);
    
    -- Layer Layer_13
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_01.png', 'Layer_13');
    element:SetHotSpot(71, 77.5);
    composition:RegisterParentInfo('Layer_13', 'Layer_25');
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 279.5);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 211.5);
    effector:SetKey(_TRACK_X, 0.1, 279.5);
    effector:SetKey(_TRACK_Y, 0.1, 222.5);
    effector:SetKey(_TRACK_X, 0.16666666666667, 279.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 211.5);
    effector:SetKey(_TRACK_X, 0.23333333333333, 279.5);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 214.5);
    effector:SetKey(_TRACK_X, 0.3, 279.5);
    effector:SetKey(_TRACK_Y, 0.3, 211.5);
    effector:SetKey(_TRACK_X, 0.36666666666667, 279.5);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 213.5);
    effector:SetKey(_TRACK_X, 0.43333333333333, 279.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 211.5);
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.1, 1.1);
    effector:SetKey(_TRACK_SY, 0.1, 1);
    effector:SetKey(_TRACK_SX, 0.16666666666667, 1);
    effector:SetKey(_TRACK_SY, 0.16666666666667, 1);
    
    -- Layer Layer_14
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_red.jpg', 'Layer_14');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_14', 'Layer_16');
    element:SetXY(155, 126);
    
    element:SetScaleX(0.6);
    element:SetScaleY(0.6);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.1, 1);
    effector:SetKey(_TRACK_O, 0.36666666666667, 0);
    
    -- Layer Layer_15
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_red.jpg', 'Layer_15');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_15', 'Layer_16');
    element:SetXY(123, 121);
    
    element:SetScaleX(0.75);
    element:SetScaleY(0.75);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.1, 1);
    effector:SetKey(_TRACK_O, 0.36666666666667, 0);
    -- Layer Layer_16
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/golova_02.png', 'Layer_16');
    element:SetHotSpot(118, 108);
    element:SetParentElement(composition);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 192);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 139);
    effector:SetKey(_TRACK_X, 0.1, 192);
    effector:SetKey(_TRACK_Y, 0.1, 150);
    effector:SetKey(_TRACK_X, 0.16666666666667, 192);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 139);
    effector:SetKey(_TRACK_X, 0.23333333333333, 192);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 142);
    effector:SetKey(_TRACK_X, 0.3, 192);
    effector:SetKey(_TRACK_Y, 0.3, 139);
    effector:SetKey(_TRACK_X, 0.36666666666667, 192);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 141);
    effector:SetKey(_TRACK_X, 0.43333333333333, 192);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 139);
    
    -- Layer Layer_17
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_17');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.06666666666667, 198);
    effector:SetKey(_TRACK_Y, 0.06666666666667, 204);
    effector:SetKey(_TRACK_X, 0.4, 198);
    effector:SetKey(_TRACK_Y, 0.4, 415);
    effector:SetKey(_TRACK_SX, 0.06666666666667, 1);
    effector:SetKey(_TRACK_SY, 0.06666666666667, 1);
    effector:SetKey(_TRACK_SX, 0.4, 1.4);
    effector:SetKey(_TRACK_SY, 0.4, 1.4);
    effector:SetKey(_TRACK_A, 0.06666666666667, 0);
    effector:SetKey(_TRACK_A, 0.4, 0.174532925);
    effector:SetKey(_TRACK_O, 0.06666666666667, 0);
    effector:SetKey(_TRACK_O, 0.2, 1);
    effector:SetKey(_TRACK_O, 0.4, 0);
    
    -- Layer Layer_18
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_red.jpg', 'Layer_18');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_18', 'Layer_20');
    element:SetXY(122, 166);
    
    element:SetScaleX(0.75);
    element:SetScaleY(0.75);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.1, 1);
    effector:SetKey(_TRACK_O, 0.4, 0);
    
    -- Layer Layer_19
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_red.jpg', 'Layer_19');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_19', 'Layer_20');
    element:SetXY(85, 174);
    
    element:SetScaleX(0.6);
    element:SetScaleY(0.6);
    element:SetAngle(0);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.1, 1);
    effector:SetKey(_TRACK_O, 0.4, 0);
    
    -- Layer Layer_20
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/golova_01.png', 'Layer_20');
    element:SetHotSpot(155.5, 160.5);
    element:SetParentElement(composition);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 850.5);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 160.5);
    effector:SetKey(_TRACK_X, 0.1, 850.5);
    effector:SetKey(_TRACK_Y, 0.1, 171.5);
    effector:SetKey(_TRACK_X, 0.16666666666667, 850.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, 160.5);
    effector:SetKey(_TRACK_X, 0.23333333333333, 850.5);
    effector:SetKey(_TRACK_Y, 0.23333333333333, 163.5);
    effector:SetKey(_TRACK_X, 0.3, 850.5);
    effector:SetKey(_TRACK_Y, 0.3, 160.5);
    effector:SetKey(_TRACK_X, 0.36666666666667, 850.5);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 162.5);
    effector:SetKey(_TRACK_X, 0.43333333333333, 850.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 160.5);
    
    -- Layer Layer_21
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_21');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    
    effector:SetKey(_TRACK_X, 0.03333333333333, 818);
    effector:SetKey(_TRACK_Y, 0.03333333333333, 210);
    effector:SetKey(_TRACK_X, 0.36666666666667, 818);
    effector:SetKey(_TRACK_Y, 0.36666666666667, 421);
    effector:SetKey(_TRACK_SX, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 0.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 0.36666666666667, 1.4);
    effector:SetKey(_TRACK_SY, 0.36666666666667, 1.4);
    effector:SetKey(_TRACK_A, 0.03333333333333, 0);
    effector:SetKey(_TRACK_A, 0.36666666666667, 0.174532925);
    effector:SetKey(_TRACK_O, 0.03333333333333, 0);
    effector:SetKey(_TRACK_O, 0.16666666666667, 1);
    effector:SetKey(_TRACK_O, 0.36666666666667, 0);
    
    -- Layer Layer_25
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Osnovanie.png', 'Layer_25');
    element:SetHotSpot(280.5, 228.5);
    element:SetParentElement(composition);
    element:SetXY(522, 548);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_26
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_04.png', 'Layer_26');
    element:SetHotSpot(65, 71.5);
    composition:RegisterParentInfo('Layer_26', 'Layer_25');
    element:SetXY(460.5, 10.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_27
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_03.png', 'Layer_27');
    element:SetHotSpot(52.5, 73);
    composition:RegisterParentInfo('Layer_27', 'Layer_25');
    element:SetXY(336.5, -19.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_28
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_02.png', 'Layer_28');
    element:SetHotSpot(59, 74);
    composition:RegisterParentInfo('Layer_28', 'Layer_25');
    element:SetXY(200.5, -19.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_29
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_01.png', 'Layer_29');
    element:SetHotSpot(66, 57);
    composition:RegisterParentInfo('Layer_29', 'Layer_25');
    element:SetXY(96.5, 30.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_30
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Schit.png', 'Layer_30');
    element:SetHotSpot(245.5, 162);
    element:SetParentElement(composition);
    element:SetXY(514, 154);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_31
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Background.png', 'Layer_31');
    element:SetHotSpot(512, 384);
    element:SetParentElement(composition);
    element:SetXY(512, 384);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_32
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Dveri_02.png', 'Layer_32');
    element:SetHotSpot(124.5, 174.5);
    element:SetParentElement(composition);
    element:SetXY(631, 347);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
    -- Layer Layer_33
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Dveri_01.png', 'Layer_33');
    element:SetHotSpot(123, 174.5);
    element:SetParentElement(composition);
    element:SetXY(389, 346);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    
	composition:Rewind(true);       --// +
    composition:PlayAt(miniGameState.timeOffset);	
end

--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--//
function auxPlayDrum(drumIndex)
    assert(drumIndex >= 1 and drumIndex <= 5);
    if (drumIndex == 1) then
        auxPlayElements('Layer_2', 'Layer_10');
    elseif (drumIndex == 2) then
        auxPlayElements('Layer_4', 'Layer_9');
    elseif (drumIndex == 3) then
        auxPlayElements('Layer_1', 'Layer_13');
    elseif (drumIndex == 4) then
        auxPlayElements('Layer_3', 'Layer_12');
    elseif (drumIndex == 5) then
        auxPlayElements('Layer_5', 'Layer_11');
    end
end

--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--//
function auxShakeHeads()
    auxPlayElements('Layer_14', 'Layer_15', 'Layer_16', 'Layer_17');
    auxPlayElements('Layer_18', 'Layer_19', 'Layer_20', 'Layer_21');    
end

--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--//
function auxGlowTile(tileIndex)
    assert(tileIndex >= 1 and tileIndex <= 3);
    if (tileIndex == 1) then
        auxPlayElements('Layer_8');
    elseif (tileIndex == 2) then
        auxPlayElements('Layer_6');
    elseif (tileIndex == 3) then
        auxPlayElements('Layer_7');
    end
end

--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--//
function auxPlayOutro()
	--//										1. replace ' -> '
	screen = miniGamePlayField;  		--//	1. +
	local element;                      --//    3. +
	local effector;				 		--//	4. +
	local zOffset = 2;                  --//    5. +
	local timeOffset = 0;				--//	6. +

	assert(miniGameState.composition);
	local composition = miniGameState.composition;
	--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	--// comment sequence creation				7. -
    local compositionDuration = 2.9;
    composition:SetDuration(compositionDuration);
    
    
    -- Layer Layer_1
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_red.jpg', 'Layer_1');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_1', 'Layer_25');
    element:SetXY(278.5, 180.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 0.33333333333333);
    
    
    effector:Play();
    
    
    -- Layer Layer_2
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_mal.jpg', 'Layer_2');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_2', 'Layer_25');
    element:SetXY(369.5, 28.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_3
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_yel.jpg', 'Layer_3');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_3', 'Layer_25');
    element:SetXY(119.5, 127.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_4
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_blue.jpg', 'Layer_4');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_4', 'Layer_25');
    element:SetXY(432.5, 131.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_5
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_green.jpg', 'Layer_5');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_5', 'Layer_25');
    element:SetXY(184.5, 12.5);
    
    element:SetScaleX(2);
    element:SetScaleY(1.4);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_6
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_blue.jpg', 'Layer_6');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_6', 'Layer_30');
    element:SetXY(272.5, 117);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_7
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_green.jpg', 'Layer_7');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_7', 'Layer_30');
    element:SetXY(248.5, 174);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(0);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_8
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/glow_yel.jpg', 'Layer_8');
    element:SetHotSpot(48, 48);
    composition:RegisterParentInfo('Layer_8', 'Layer_30');
    element:SetXY(241.5, 64);
    
    element:SetScaleX(1.08888888888889);
    element:SetScaleY(1.08888888888889);
    element:SetAngle(0);
    element:SetOpacity(0.44444444444444);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.86666666666667);
    
    
    effector:Play();
    
    
    -- Layer Layer_9
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_02.png', 'Layer_9');
    element:SetHotSpot(66, 68.5);
    composition:RegisterParentInfo('Layer_9', 'Layer_25');
    element:SetXY(437.5, 151.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_10
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_03.png', 'Layer_10');
    element:SetHotSpot(58.5, 60);
    composition:RegisterParentInfo('Layer_10', 'Layer_25');
    element:SetXY(369.5, 43.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_11
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_04.png', 'Layer_11');
    element:SetHotSpot(58.5, 60);
    composition:RegisterParentInfo('Layer_11', 'Layer_25');
    element:SetXY(185.5, 39.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_12
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_05.png', 'Layer_12');
    element:SetHotSpot(66, 68.5);
    composition:RegisterParentInfo('Layer_12', 'Layer_25');
    element:SetXY(117.5, 148.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_13
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Baraban_01.png', 'Layer_13');
    element:SetHotSpot(71, 77.5);
    composition:RegisterParentInfo('Layer_13', 'Layer_25');
    element:SetXY(279.5, 211.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_16
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/golova_02.png', 'Layer_16');
    element:SetHotSpot(118, 108);
    element:SetParentElement(composition);
    element:SetXY(192, 139);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_20
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/golova_01.png', 'Layer_20');
    element:SetHotSpot(155.5, 160.5);
    element:SetParentElement(composition);
    element:SetXY(850.5, 160.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_22
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Znaki_03.png', 'Layer_22');
    element:SetHotSpot(31, 30.5);
    composition:RegisterParentInfo('Layer_22', 'Layer_30');
    element:SetXY(241.5, 65);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_23
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Znaki_02.png', 'Layer_23');
    element:SetHotSpot(30, 30.5);
    composition:RegisterParentInfo('Layer_23', 'Layer_30');
    element:SetXY(273.5, 119.5);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_24
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Znaki_01.png', 'Layer_24');
    element:SetHotSpot(30, 30);
    composition:RegisterParentInfo('Layer_24', 'Layer_30');
    element:SetXY(248, 177);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_25
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Osnovanie.png', 'Layer_25');
    element:SetHotSpot(280.5, 228.5);
    element:SetParentElement(composition);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 1.36666666666667, 522);
    effector:SetKey(_TRACK_Y, 1.36666666666667, 548);
    effector:SetKey(_TRACK_X, 2.6, 522);
    effector:SetKey(_TRACK_Y, 2.6, 1200);
    
    effector:Play();
    
    
    -- Layer Layer_26
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_04.png', 'Layer_26');
    element:SetHotSpot(65, 71.5);
    composition:RegisterParentInfo('Layer_26', 'Layer_25');
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 0.43333333333333, 460.5);
    effector:SetKey(_TRACK_Y, 0.43333333333333, 10.5);
    effector:SetKey(_TRACK_X, 1.1, 379.5);
    effector:SetKey(_TRACK_Y, 1.1, 110.5);
    
    effector:Play();
    
    
    -- Layer Layer_27
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_03.png', 'Layer_27');
    element:SetHotSpot(52.5, 73);
    composition:RegisterParentInfo('Layer_27', 'Layer_25');
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 0.16666666666667, 336.5);
    effector:SetKey(_TRACK_Y, 0.16666666666667, -19.5);
    effector:SetKey(_TRACK_X, 0.56666666666667, 391.5);
    effector:SetKey(_TRACK_Y, 0.56666666666667, 102.5);
    
    effector:Play();
    
    
    -- Layer Layer_28
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_02.png', 'Layer_28');
    element:SetHotSpot(59, 74);
    composition:RegisterParentInfo('Layer_28', 'Layer_25');
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 0, 200.5);
    effector:SetKey(_TRACK_Y, 0, -19.5);
    effector:SetKey(_TRACK_X, 0.56666666666667, 123.5);
    effector:SetKey(_TRACK_Y, 0.56666666666667, 92.5);
    
    effector:Play();
    
    
    -- Layer Layer_29
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Truba_01.png', 'Layer_29');
    element:SetHotSpot(66, 57);
    composition:RegisterParentInfo('Layer_29', 'Layer_25');
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 0.26666666666667, 96.5);
    effector:SetKey(_TRACK_Y, 0.26666666666667, 30.5);
    effector:SetKey(_TRACK_X, 1.16666666666667, 190.5);
    effector:SetKey(_TRACK_Y, 1.16666666666667, 92.5);
    
    effector:Play();
    
    
    -- Layer Layer_30
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Schit.png', 'Layer_30');
    element:SetHotSpot(245.5, 162);
    element:SetParentElement(composition);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 0.33333333333333, 514);
    effector:SetKey(_TRACK_Y, 0.33333333333333, 154);
    effector:SetKey(_TRACK_X, 1.73333333333333, 514);
    effector:SetKey(_TRACK_Y, 1.73333333333333, 0);
    effector:SetKey(_TRACK_X, 1.83333333333333, 514);
    effector:SetKey(_TRACK_Y, 1.83333333333333, 5);
    
    effector:Play();
    
    
    -- Layer Layer_331
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_331');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0.2, 0.96666666666667);
    
    effector:SetKey(_TRACK_X, 0.2, 362);
    effector:SetKey(_TRACK_Y, 0.2, -163);
    effector:SetKey(_TRACK_X, 0.93333333333333, 362);
    effector:SetKey(_TRACK_Y, 0.93333333333333, 393);
    effector:SetKey(_TRACK_SX, 0.2, 1.5);
    effector:SetKey(_TRACK_SY, 0.2, 1.5);
    effector:SetKey(_TRACK_SX, 0.6, 1.8);
    effector:SetKey(_TRACK_SY, 0.6, 1.8);
    effector:SetKey(_TRACK_A, 0.2, 0);
    effector:SetKey(_TRACK_A, 0.93333333333333, 0.523598775);
    effector:SetKey(_TRACK_O, 0.2, 0.8);
    effector:SetKey(_TRACK_O, 0.6, 1);
    effector:SetKey(_TRACK_O, 0.93333333333333, 0.4);
    
    effector:Play();
    
    
    -- Layer Layer_332
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_332');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0.43333333333333, 1.2);
    
    effector:SetKey(_TRACK_X, 0.43333333333333, 616);
    effector:SetKey(_TRACK_Y, 0.43333333333333, -167.725162560525);
    effector:SetKey(_TRACK_X, 1.16666666666667, 614);
    effector:SetKey(_TRACK_Y, 1.16666666666667, 451);
    effector:SetKey(_TRACK_SX, 0.43333333333333, 1.5);
    effector:SetKey(_TRACK_SY, 0.43333333333333, 1.5);
    effector:SetKey(_TRACK_SX, 0.83333333333333, 1.8);
    effector:SetKey(_TRACK_SY, 0.83333333333333, 1.8);
    effector:SetKey(_TRACK_A, 0.43333333333333, 0);
    effector:SetKey(_TRACK_A, 1.16666666666667, -0.6108652375);
    effector:SetKey(_TRACK_O, 0.43333333333333, 0.8);
    effector:SetKey(_TRACK_O, 0.83333333333333, 1);
    effector:SetKey(_TRACK_O, 1.16666666666667, 0.4);
    
    effector:Play();
    
    
    -- Layer Layer_333
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_333');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    effector:SetLifeTime(1.6, 2.36666666666667);
    
    effector:SetKey(_TRACK_X, 1.6, 526);
    effector:SetKey(_TRACK_Y, 1.6, -167.725162560525);
    effector:SetKey(_TRACK_X, 2.33333333333333, 524);
    effector:SetKey(_TRACK_Y, 2.33333333333333, 451);
    effector:SetKey(_TRACK_SX, 1.6, 1.5);
    effector:SetKey(_TRACK_SY, 1.6, 1.5);
    effector:SetKey(_TRACK_SX, 2, 1.8);
    effector:SetKey(_TRACK_SY, 2, 1.8);
    effector:SetKey(_TRACK_A, 1.6, 0);
    effector:SetKey(_TRACK_A, 2.33333333333333, -0.6108652375);
    effector:SetKey(_TRACK_O, 1.6, 0.8);
    effector:SetKey(_TRACK_O, 2, 1);
    effector:SetKey(_TRACK_O, 2.33333333333333, 0.4);
    
    effector:Play();
    
    
    -- Layer Layer_334
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_334');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    effector:SetLifeTime(2.03333333333333, 2.8);
    
    effector:SetKey(_TRACK_X, 2.03333333333333, 468);
    effector:SetKey(_TRACK_Y, 2.03333333333333, -145.725162560525);
    effector:SetKey(_TRACK_X, 2.76666666666667, 466);
    effector:SetKey(_TRACK_Y, 2.76666666666667, 473);
    effector:SetKey(_TRACK_SX, 2.03333333333333, 1);
    effector:SetKey(_TRACK_SY, 2.03333333333333, 1);
    effector:SetKey(_TRACK_SX, 2.43333333333333, 1.4);
    effector:SetKey(_TRACK_SY, 2.43333333333333, 1.4);
    effector:SetKey(_TRACK_A, 2.03333333333333, 0);
    effector:SetKey(_TRACK_A, 2.76666666666667, 0.872664625);
    effector:SetKey(_TRACK_O, 2.03333333333333, 0.8);
    effector:SetKey(_TRACK_O, 2.43333333333333, 1);
    effector:SetKey(_TRACK_O, 2.76666666666667, 0.4);
    
    effector:Play();
    
    
    -- Layer Layer_31
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Background.png', 'Layer_31');
    element:SetHotSpot(512, 384);
    element:SetParentElement(composition);
    element:SetXY(512, 384);
    
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    
    effector:Play();
    
    
    -- Layer Layer_32
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Dveri_02.png', 'Layer_32');
    element:SetHotSpot(124.5, 174.5);
    element:SetParentElement(composition);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 1.93333333333333, 648);
    effector:SetKey(_TRACK_Y, 1.93333333333333, 347);
    effector:SetKey(_TRACK_X, 2.03333333333333, 652);
    effector:SetKey(_TRACK_Y, 2.03333333333333, 347);
    effector:SetKey(_TRACK_X, 2.1, 650);
    effector:SetKey(_TRACK_Y, 2.1, 347);
    effector:SetKey(_TRACK_X, 2.16666666666667, 652);
    effector:SetKey(_TRACK_Y, 2.16666666666667, 347);
    effector:SetKey(_TRACK_X, 2.66666666666667, 863);
    effector:SetKey(_TRACK_Y, 2.66666666666667, 345);
    effector:SetKey(_TRACK_X, 2.76666666666667, 854);
    effector:SetKey(_TRACK_Y, 2.76666666666667, 345);
    
    effector:Play();
    
    
    -- Layer Layer_33
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/Dveri_01.png', 'Layer_33');
    element:SetHotSpot(123, 174.5);
    element:SetParentElement(composition);
    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.9);
    
    effector:SetKey(_TRACK_X, 1.96666666666667, 407);
    effector:SetKey(_TRACK_Y, 1.96666666666667, 346);
    effector:SetKey(_TRACK_X, 2.06666666666667, 405);
    effector:SetKey(_TRACK_Y, 2.06666666666667, 346);
    effector:SetKey(_TRACK_X, 2.13333333333333, 407);
    effector:SetKey(_TRACK_Y, 2.13333333333333, 346);
    effector:SetKey(_TRACK_X, 2.2, 404);
    effector:SetKey(_TRACK_Y, 2.2, 346);
    effector:SetKey(_TRACK_X, 2.7, 200);
    effector:SetKey(_TRACK_Y, 2.7, 346);
    effector:SetKey(_TRACK_X, 2.8, 212);
    effector:SetKey(_TRACK_Y, 2.8, 346);
    
    effector:Play();
    
    
    -- Layer Layer_335
    local element = auxCreateCompositionElement(composition, 'data/Texture/Minigames/DrumsGate/dust_1.png', 'Layer_335');
    element:SetHotSpot(102, 102);
    element:SetParentElement(composition);
    
    effector = element:GetEffector();
    effector:SetLifeTime(2.13333333333333, 2.9);
    
    effector:SetKey(_TRACK_X, 2.13333333333333, 566);
    effector:SetKey(_TRACK_Y, 2.13333333333333, -75.7251625605248);
    effector:SetKey(_TRACK_X, 2.86666666666667, 564);
    effector:SetKey(_TRACK_Y, 2.86666666666667, 543);
    effector:SetKey(_TRACK_SX, 0.56666666666667, 0.6);
    effector:SetKey(_TRACK_SY, 0.56666666666667, 0.6);
    effector:SetKey(_TRACK_SX, 2.13333333333333, 1);
    effector:SetKey(_TRACK_SY, 2.13333333333333, 1);
    effector:SetKey(_TRACK_SX, 2.53333333333333, 1.4);
    effector:SetKey(_TRACK_SY, 2.53333333333333, 1.4);
    effector:SetKey(_TRACK_A, 2.13333333333333, 0);
    effector:SetKey(_TRACK_A, 2.86666666666667, -0.174532925);
    effector:SetKey(_TRACK_O, 2.13333333333333, 0.8);
    effector:SetKey(_TRACK_O, 2.53333333333333, 1);
    effector:SetKey(_TRACK_O, 2.86666666666667, 0);
    
    effector:Play();
    
    composition:PlayAt(timeOffset);

	--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  	TimerDoString('miniGameState.completed = true;', compositionDuration, miniGamePlayField:GetTimer());
end


--// additional (logic) routines - - - - - - - - - - - - - - - - - - - -
--// ...
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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.delayPeriodPassed == false and miniGameState.timeElapsed > miniGameState.delayPeriod) then
        miniGameState.delayPeriodPassed = true;
        auxShowButton(false);
    end
end

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

function OnObjectMouseDown(object)
    local objectName = object:GetName();

	local drumNameLen = string.len('actZoneDrum');
	if (string.sub(objectName,1, drumNameLen) == 'actZoneDrum') and miniGameState.locked == false then
		local drumIndex = tonumber(string.sub(objectName, drumNameLen + 1, drumNameLen + 2));

		auxPlayDrum(drumIndex);
		miniGameState.locked = true;
		PlaySound('L01S0'..drumIndex);
		
		if(drumIndex == Consecution[cur_consecution][cur_razklad][cur_down]) then
			cur_down = cur_down + 1;
			if(Consecution[cur_consecution][cur_razklad][cur_down] == nil) then
				cur_down = 1;
				auxGlowTile(cur_consecution);
				
				cur_consecution = cur_consecution + 1;
				if(cur_consecution > 3) then
					--TODO финальный ролик и выход
					miniGameState.completed = true;
					auxShowButton(true);
					cur_text = GetTextString('MINIGAME_DRUMSGATE_TEXT2');
					auxShowText();
					TimerDoString('auxHideText()', 2.0, miniGamePlayField:GetTimer())
					
					TimerDoString('PlaySound("L01S07", true)', 0.4, miniGamePlayField:GetTimer());
					TimerDoString('StopSound("L01S07");', 2.5, miniGamePlayField:GetTimer());
--					GetGameApp():SetCustomCursorVisible(true);
					for i = 1,3 do
						if Elements[i]:GetOpacity() > 0.0 then
							Elements[i]:SetVisible(false);
						end
					end
        			auxPlayOutro();
				else
					PlaySound('L01S06');
					
					if(cur_consecution == 2) then
						cur_text = GetTextString('MINIGAME_DRUMSGATE_TEXT3');
					end
					if(cur_consecution == 3) then
						cur_text = GetTextString('MINIGAME_DRUMSGATE_TEXT4');
					end
					auxShowText();
					TimerDoString('auxHideText()', 2.0, miniGamePlayField:GetTimer())
					
					miniGamePlayField:GetObject('Znaki_0'..(cur_consecution - 1)):ChangeOpacity(0.0, 1.0, 0.5);
					TimerDoString('PlayConsecution(1)', 2.5, miniGamePlayField:GetTimer());
					cur_razklad = math.random(3);
				end
			else
				TimerDoString('miniGameState.locked = false;', 0.1, miniGamePlayField:GetTimer())
			end
		else
			PlaySound('L01S08');
		
			cur_text = GetTextString('MINIGAME_DRUMSGATE_TEXT5');
			auxShowText();
			TimerDoString('auxHideText()', 2.0, miniGamePlayField:GetTimer())
					
			cur_razklad = math.random(3);
			miniGameState.locked = true;
			cur_down = 1;
			if(cur_consecution > 1) then
				cur_consecution = cur_consecution - 1;
			end
			
			if Elements[cur_consecution]:GetOpacity() > 0.0 then
				Elements[cur_consecution]:ChangeOpacity(1.0, 0.0, 0.5);
			end
			auxShakeHeads();
			TimerDoString('PlayConsecution(1)', 2.5, miniGamePlayField:GetTimer());
		end
	end
end
function OnObjectMouseUp(object)
end

function OnObjectRightMouseDown(object)
end
function OnObjectRightMouseUp(object)
end

function OnMouseMove(previousPos, currentPos)
end

function OnObjectMouseEnter(object)
	local objectName = object:GetName();
	local drumNameLen = string.len('actZoneDrum');
	
	if (string.sub(objectName,1, drumNameLen) == 'actZoneDrum') and miniGameState.locked == false then
		local drumIndex = tonumber(string.sub(objectName, drumNameLen + 1, drumNameLen + 2));
		local sound_name = 'L01S0'..(drumIndex + 8);
		local volume = GetSoundVolume(sound_name);
		SetSoundVolume(sound_name, 0.1);
		--PlaySound(sound_name);
		SetSoundVolume(sound_name, volume);
	end
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('actZoneDrum1',anim,613,340,101,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('actZoneDrum2',anim,678,446,101,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('actZoneDrum3',anim,520,506,101,0,1.3,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('actZoneDrum4',anim,359,456,101,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('actZoneDrum5',anim,425,336,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/DrumsGate/miniGameBackground.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	play_field:CreateObject('miniGameBackground',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/DrumsGate/Znaki_03.png',0,0,62,61,1,0)
	anim:SetHotSpot(31,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Znaki_01',anim,509,57,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/DrumsGate/Znaki_02.png',0,0,60,61,1,0)
	anim:SetHotSpot(30,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Znaki_02',anim,542,111.5,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/DrumsGate/Znaki_01.png',0,0,60,60,1,0)
	anim:SetHotSpot(30,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('Znaki_03',anim,516,169,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/DrumsGate/BG01_00.jpg',0,0,522,392,1,0)
	anim:SetHotSpot(261,196)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('BG01_00',anim,521,367,1,0,1,1)
end

function FreeData()
end
-- CLEAR_ON_SAVE_END
