--// Local auxiliary functions - - - - - - - - - - - - - - - - - - - - - - - -

--// 1.	rename:					" -> '
--// 2. comment root composition with texture "createComposition20_Near_old_ship = function()"
--// 3. add auxiliaru routines for managing animations: 
--		auxPlayNearCollapsedShipEnvAnimation(), 
--		auxGetNearCollapsedShipEnvAnimation(), 
--		auxCreateNearCollapsedShipEnvAnimations()
--// 4. replace CreateCompositionElement() with auxCreateCompositionElement() for some corrections ...

------------------------------------------------------------------------------
--
function auxPlayNearCollapsedShipEnvAnimation(compositionName)
    local composition = auxGetNearCollapsedShipEnvAnimation(compositionName);
    composition:SetVisible(true);
    composition:Play();
end

------------------------------------------------------------------------------
--
function auxHideNearCollapsedShipEnvAnimation(compositionName)
    local composition = auxGetNearCollapsedShipEnvAnimation(compositionName);
    composition:Stop();
    composition:SetVisible(false);
end

------------------------------------------------------------------------------
--
function auxGetNearCollapsedShipEnvAnimation(compositionName)
    assert(nearCollapsedShipEnvCompositions ~= nil and compositionName ~= nil);
	assert(nearCollapsedShipEnvCompositions[compositionName] ~= nil and 'Composition with specified name not exists !');

    return nearCollapsedShipEnvCompositions[compositionName];
end

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

function CreateComposition(parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic)
    assert(parent ~= nil and compositionRoutine ~= nil and name ~= nil and z ~= nil and duration ~= nil);

    local element = compositionRoutine();
    element:SetName(name);
    element:SetHotSpot(hotSpotX,hotSpotY);
    element:SetXY(x, y);
    assert(z - parent:GetZ());
    element:SetZ(z - parent:GetZ());
    element:AttachTo(parent);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);
    
    if (isCyclic == true) then
        element:SetDuration(duration);
        element:SetCyclic(true);
    end
	element:Stop();
    element:SetVisible(false);
    element:AssignClippingRect(parent);
	element:SetConsiderParentOpacity(true);

	return element;
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function auxCreateCompositionElement(resourceName)
	local element = CreateCompositionElement(resourceName);
    local texName = string.sub(resourceName, string.len('data/Texture/Scenes/19_NearCollapsedShip/Animations/Env/') + 1);


	--// set up saegulls animation
	if (texName == 'sg_[0000-0009].png') then
		local anim = element:GetTexture();
		anim:Stop();
		anim:SetTextureRect(0,0, 40,22);
		anim:SetFrames(10);
		anim:SetFrame(0);
		anim:SetSpeed(30.0);
		anim:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
		anim:Play();
    end
    --// set up crab animation
	if (texName == 'Crab_[0000-0007].png') then
		local anim = element:GetTexture();
		anim:Stop();
		anim:SetTextureRect(0,0, 108,101);
		anim:SetFrames(8);
		anim:SetFrame(0);
		anim:SetSpeed(30.0);
		anim:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
		anim:Play();
    end
    --// set additive alpha blending mode for light & flare objects without alpha chanel (*.jpg)
    if (texName == 'EF_light1_01.jpg' or
		texName == 'EF_wave2_01.png') then

        element:GetTexture():SetBlendMode(0);
    end
	return element;
end

------------------------------------------------------------------------------
--
function auxCreateNearCollapsedShipEnvAnimations(parent)
    assert(parent ~= nil);
    nearCollapsedShipEnvCompositions = {};
    local CreateAndRegisterComposition = function (parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic)
        local element = CreateComposition(parent, compositionRoutine, name, x,y,z, hotSpotX,hotSpotY, duration, isCyclic);
        nearCollapsedShipEnvCompositions[element:GetName()] = element;
    end
    
    CreateAndRegisterComposition(parent, createCompositionEnvBack, 	'EnvBack',	0,0,100.0, 512,384, 10, true);
    CreateAndRegisterComposition(parent, createCompositionEnvFront, 'EnvFront',	0,0,108.0, 512,384, 10, true);
end

------------------------------------------------------------------------------
--
--createComposition20_Near_old_ship = function()
--
--    local composition20_Near_old_ship = CreateCompositionSequence();
--    local compositionDuration = 10;
--    composition20_Near_old_ship:SetDuration(compositionDuration);
--
--
--    -- Layer Layer_1
--    local element = createCompositionEnvFront();
--    element:SetName('Layer_1');
--    composition20_Near_old_ship:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(composition20_Near_old_ship);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--
--    -- Layer Layer_2
--    local element = createCompositionEnvBack();
--    element:SetName('Layer_2');
--    composition20_Near_old_ship:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(composition20_Near_old_ship);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--
--    -- Layer BG
--    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/20_Near_old_ship.jpg');
--    element:SetName('BG');
--    composition20_Near_old_ship:AddElement(element);
--    element:SetHotSpot(512, 384);
--    element:SetParentElement(composition20_Near_old_ship);
--    element:SetXY(512, 384);
--
--    element:SetScaleX(1);
--    element:SetScaleY(1);
--    element:SetAngle(0);
--    element:SetOpacity(1);
--
--    effector = element:GetEffector();
--    effector:SetLifeTime(0, 10);
--
--
--    effector:Play();
--
--    composition20_Near_old_ship:Play();
--
--    return composition20_Near_old_ship;
--end

createCompositionEnvBack = function()

    local compositionEnvBack = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionEnvBack:SetDuration(compositionDuration);


    -- Layer Seagull
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/sg_[0000-0009].png');
    element:SetName('Seagull');
    compositionEnvBack:AddElement(element);
    element:SetHotSpot(20, 11);
    element:SetParentElement(compositionEnvBack);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_X, 0, 34.5945892333984);
    effector:SetKey(_TRACK_Y, 0, -32.2882843017578);
    effector:SetKey(_TRACK_X, 2, 138.378372192383);
    effector:SetKey(_TRACK_Y, 2, 2.30630493164063);
    effector:SetKey(_TRACK_X, 4.12, 248.896392822266);
    effector:SetKey(_TRACK_Y, 4.12, 27.2162170410156);
    effector:SetKey(_TRACK_X, 6.72, 368.761260986328);
    effector:SetKey(_TRACK_Y, 6.72, 51.0855865478516);
    effector:SetKey(_TRACK_X, 9, 466.463973999023);
    effector:SetKey(_TRACK_Y, 9, 64.6486358642578);
    effector:SetKey(_TRACK_X, 9.96, 509.734237670898);
    effector:SetKey(_TRACK_Y, 9.96, 66.4143981933594);
    effector:SetKey(_TRACK_SX, 0, -1.07432424801566);
    effector:SetKey(_TRACK_SY, 0, 1);
    effector:SetKey(_TRACK_SX, 9.96, -0.4);
    effector:SetKey(_TRACK_SY, 9.96, 0.4);

    effector:Play();


    -- Layer Waves
    local element = createCompositionWaves2();
    element:SetName('Waves');
    compositionEnvBack:AddElement(element);
    element:SetHotSpot(512, 384);
    element:SetParentElement(compositionEnvBack);
    element:SetXY(512, 384);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);


    effector:Play();


    -- Layer Wavers_all
    local element = createCompositionWavesAll();
    element:SetName('Wavers_all');
    compositionEnvBack:AddElement(element);
    element:SetHotSpot(512, 384);
    element:SetParentElement(compositionEnvBack);
    element:SetXY(512, 384);

    element:SetScaleX(1);
    element:SetScaleY(1);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);


    effector:Play();

    compositionEnvBack:Play();

    return compositionEnvBack;
end

createCompositionEnvFront = function()

    local compositionEnvFront = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionEnvFront:SetDuration(compositionDuration);


    -- Layer Light
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_light1_01.jpg');
    element:SetName('Light');
    compositionEnvFront:AddElement(element);
    element:SetHotSpot(90.015625, 78.2156219482422);
    element:SetParentElement(compositionEnvFront);
    element:SetXY(503.927917480469, 154.522521972656);


    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_SX, 0, 4);
    effector:SetKey(_TRACK_SY, 0, 4);
    effector:SetKey(_TRACK_SX, 1.36, 4.5);
    effector:SetKey(_TRACK_SY, 1.36, 4.5);
    effector:SetKey(_TRACK_SX, 2.52, 3.5);
    effector:SetKey(_TRACK_SY, 2.52, 3.5);
    effector:SetKey(_TRACK_SX, 3.8, 4);
    effector:SetKey(_TRACK_SY, 3.8, 4);
    effector:SetKey(_TRACK_SX, 5.44, 3.5);
    effector:SetKey(_TRACK_SY, 5.44, 3.5);
    effector:SetKey(_TRACK_SX, 7.2, 3.8);
    effector:SetKey(_TRACK_SY, 7.2, 3.8);
    effector:SetKey(_TRACK_SX, 8.52, 4.2);
    effector:SetKey(_TRACK_SY, 8.52, 4.2);
    effector:SetKey(_TRACK_SX, 9.96, 4);
    effector:SetKey(_TRACK_SY, 9.96, 4);
    effector:SetKey(_TRACK_A, 0, 0);
    effector:SetKey(_TRACK_A, 0.92, 0.04407407685039);
    effector:SetKey(_TRACK_A, 1.36, 0.07652688143461);
    effector:SetKey(_TRACK_A, 2.24, 0.06805794060906);
    effector:SetKey(_TRACK_A, 3.44, 0.03128375128437);
    effector:SetKey(_TRACK_A, 4.24, 0.04563326164134);
    effector:SetKey(_TRACK_A, 4.92, 0.09215986931936);
    effector:SetKey(_TRACK_A, 5.8, 0.06272131720168);
    effector:SetKey(_TRACK_A, 6.64, -0.02620438303344);
    effector:SetKey(_TRACK_A, 7.44, 0.00875124164337);
    effector:SetKey(_TRACK_A, 8.2, 0.09298548962539);
    effector:SetKey(_TRACK_A, 9.04, 0.06269465541943);
    effector:SetKey(_TRACK_A, 9.96, 0);
    effector:SetKey(_TRACK_O, 0, 0.2);
    effector:SetKey(_TRACK_O, 1.68, 0.5);
    effector:SetKey(_TRACK_O, 2.84, 0.1);
    effector:SetKey(_TRACK_O, 4.04, 0.35);
    effector:SetKey(_TRACK_O, 5.72, 0.15);
    effector:SetKey(_TRACK_O, 7.44, 0.4);
    effector:SetKey(_TRACK_O, 8.88, 0.1);
    effector:SetKey(_TRACK_O, 9.96, 0.2);

    effector:Play();


    -- Layer Crab3
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/Crab_[0000-0007].png');
    element:SetName('Crab3');
    compositionEnvFront:AddElement(element);
    element:SetHotSpot(51.5, 39.5);
    element:SetParentElement(compositionEnvFront);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10.1333333333333);

    effector:SetKey(_TRACK_X, 0, 308.468475341797);
    effector:SetKey(_TRACK_Y, 0, 555.220718383789);
    effector:SetKey(_TRACK_X, 0.48, 302.468475341797);
    effector:SetKey(_TRACK_Y, 0.48, 562.220718383789);
    effector:SetKey(_TRACK_X, 0.84, 291.218475341797);
    effector:SetKey(_TRACK_Y, 0.84, 566.220718383789);
    effector:SetKey(_TRACK_X, 1.16, 285.968475341797);
    effector:SetKey(_TRACK_Y, 1.16, 573.970718383789);
    effector:SetKey(_TRACK_X, 1.4, 293.968475341797);
    effector:SetKey(_TRACK_Y, 1.4, 577.720718383789);
    effector:SetKey(_TRACK_X, 1.72, 303.218475341797);
    effector:SetKey(_TRACK_Y, 1.72, 581.720718383789);
    effector:SetKey(_TRACK_X, 2.08, 295.718475341797);
    effector:SetKey(_TRACK_Y, 2.08, 584.220718383789);
    effector:SetKey(_TRACK_X, 2.4, 280.718475341797);
    effector:SetKey(_TRACK_Y, 2.4, 582.720718383789);
    effector:SetKey(_TRACK_X, 2.8, 271.218475341797);
    effector:SetKey(_TRACK_Y, 2.8, 589.720718383789);
    effector:SetKey(_TRACK_X, 3.68, 263.718475341797);
    effector:SetKey(_TRACK_Y, 3.68, 590.220718383789);
    effector:SetKey(_TRACK_X, 3.72, 261.468475341797);
    effector:SetKey(_TRACK_Y, 3.72, 589.220718383789);
    effector:SetKey(_TRACK_X, 4, 253.718475341797);
    effector:SetKey(_TRACK_Y, 4, 594.470718383789);
    effector:SetKey(_TRACK_X, 4.28, 243.218475341797);
    effector:SetKey(_TRACK_Y, 4.28, 596.720718383789);
    effector:SetKey(_TRACK_X, 4.64, 230.468475341797);
    effector:SetKey(_TRACK_Y, 4.64, 595.220718383789);
    effector:SetKey(_TRACK_X, 4.96, 218.718475341797);
    effector:SetKey(_TRACK_Y, 4.96, 592.220718383789);
    effector:SetKey(_TRACK_X, 5.24, 208.468475341797);
    effector:SetKey(_TRACK_Y, 5.24, 589.470718383789);
    effector:SetKey(_TRACK_X, 5.6, 193.218475341797);
    effector:SetKey(_TRACK_Y, 5.6, 587.970718383789);
    effector:SetKey(_TRACK_X, 6, 176.968475341797);
    effector:SetKey(_TRACK_Y, 6, 587.470718383789);
    effector:SetKey(_TRACK_X, 6.2, 171.718475341797);
    effector:SetKey(_TRACK_Y, 6.2, 586.720718383789);
    effector:SetKey(_TRACK_X, 6.84, 155.968475341797);
    effector:SetKey(_TRACK_Y, 6.84, 585.470718383789);
    effector:SetKey(_TRACK_SX, 0, 0.19519400287674);
    effector:SetKey(_TRACK_SY, 0, 0.1939166889662);
    effector:SetKey(_TRACK_SX, 3.68, 0.19519400287674);
    effector:SetKey(_TRACK_SY, 3.68, 0.1939166889662);
    effector:SetKey(_TRACK_SX, 3.72, 0.25);
    effector:SetKey(_TRACK_SY, 3.72, 0.24836404565238);
    effector:SetKey(_TRACK_A, 0, 0);
    effector:SetKey(_TRACK_A, 0.4, -0.36490778050452);
    effector:SetKey(_TRACK_A, 2.4, -0.0081969102691);
    effector:SetKey(_TRACK_A, 4, -0.2210434833027);
    effector:SetKey(_TRACK_A, 4.96, 0.09869997685217);
    effector:SetKey(_TRACK_A, 5.24, 0.05217774278231);
    effector:SetKey(_TRACK_A, 6, 0.0027674828734);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 0.48, 1);
    effector:SetKey(_TRACK_O, 2.76, 1);
    effector:SetKey(_TRACK_O, 2.8, 0);
    effector:SetKey(_TRACK_O, 3.68, 0);
    effector:SetKey(_TRACK_O, 3.72, 1);
    effector:SetKey(_TRACK_O, 6.2, 1);
    effector:SetKey(_TRACK_O, 6.28, 0);

    effector:Play();


    -- Layer Crab2
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/Crab_[0000-0007].png');
    element:SetName('Crab2');
    compositionEnvFront:AddElement(element);
    element:SetHotSpot(50, 41.5);
    element:SetParentElement(compositionEnvFront);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10.1333333333333);

    effector:SetKey(_TRACK_X, 0, -53.0450439453125);
    effector:SetKey(_TRACK_Y, 0, 725.333343505859);
    effector:SetKey(_TRACK_X, 1.18703125, 31.1351318359375);
    effector:SetKey(_TRACK_Y, 1.18703125, 712.648666381836);
    effector:SetKey(_TRACK_X, 2.0575390625, 53.1351318359375);
    effector:SetKey(_TRACK_Y, 2.0575390625, 679.648666381836);
    effector:SetKey(_TRACK_X, 2.84890625, 25.1351318359375);
    effector:SetKey(_TRACK_Y, 2.84890625, 639.648666381836);
    effector:SetKey(_TRACK_X, 3.5611328125, 39.1351318359375);
    effector:SetKey(_TRACK_Y, 3.5611328125, 611.648666381836);
    effector:SetKey(_TRACK_X, 4.12, 56.9893237467956);
    effector:SetKey(_TRACK_Y, 4.12, 605.936151235321);
    effector:SetKey(_TRACK_X, 4.76, 71.6351318359375);
    effector:SetKey(_TRACK_Y, 4.76, 592.148666381836);
    effector:SetKey(_TRACK_X, 5.16, 87.6351318359375);
    effector:SetKey(_TRACK_Y, 5.16, 587.148666381836);
    effector:SetKey(_TRACK_X, 5.6, 78.1351318359375);
    effector:SetKey(_TRACK_Y, 5.6, 585.648666381836);
    effector:SetKey(_TRACK_X, 6.12, 69.3851318359375);
    effector:SetKey(_TRACK_Y, 6.12, 580.398666381836);
    effector:SetKey(_TRACK_X, 6.8, 56.1351318359375);
    effector:SetKey(_TRACK_Y, 6.8, 581.898666381836);
    effector:SetKey(_TRACK_X, 7.48, 42.6351318359375);
    effector:SetKey(_TRACK_Y, 7.48, 588.148666381836);
    effector:SetKey(_TRACK_X, 8.16, 29.3851318359375);
    effector:SetKey(_TRACK_Y, 8.16, 585.898666381836);
    effector:SetKey(_TRACK_X, 8.76, 17.3851318359375);
    effector:SetKey(_TRACK_Y, 8.76, 578.398666381836);
    effector:SetKey(_TRACK_X, 9.32, 5.8851318359375);
    effector:SetKey(_TRACK_Y, 9.32, 569.898666381836);
    effector:SetKey(_TRACK_X, 9.88, -12.1148681640625);
    effector:SetKey(_TRACK_Y, 9.88, 561.898666381836);
    effector:SetKey(_TRACK_SX, 0, 0.8);
    effector:SetKey(_TRACK_SY, 0, 0.8);
    effector:SetKey(_TRACK_SX, 2.84890625, 0.5);
    effector:SetKey(_TRACK_SY, 2.84890625, 0.5);
    effector:SetKey(_TRACK_SX, 6.28, 0.4);
    effector:SetKey(_TRACK_SY, 6.28, 0.4);
    effector:SetKey(_TRACK_SX, 7.76, 0.35);
    effector:SetKey(_TRACK_SY, 7.76, 0.35);
    effector:SetKey(_TRACK_SX, 9.88, 0.3);
    effector:SetKey(_TRACK_SY, 9.88, 0.3);
    effector:SetKey(_TRACK_A, 0, 0);
    effector:SetKey(_TRACK_A, 1.18703125, -0.18882264438032);
    effector:SetKey(_TRACK_A, 1.64, -0.29575080186267);
    effector:SetKey(_TRACK_A, 2.0575390625, 0.46078688312738);
    effector:SetKey(_TRACK_A, 2.4, -0.10201718515755);
    effector:SetKey(_TRACK_A, 2.84890625, -0.15063928455265);
    effector:SetKey(_TRACK_A, 3.2, -0.02344665309094);
    effector:SetKey(_TRACK_A, 3.5611328125, -0.38706779348362);
    effector:SetKey(_TRACK_A, 4.12, -0.16545616090531);
    effector:SetKey(_TRACK_A, 4.76, -0.37193862676135);
    effector:SetKey(_TRACK_A, 5.6, 0.29268218457292);
    effector:SetKey(_TRACK_A, 6.12, -0.03134206540957);
    effector:SetKey(_TRACK_A, 6.8, -0.16504744663166);
    effector:SetKey(_TRACK_A, 7.48, -0.29607172396686);
    effector:SetKey(_TRACK_A, 8.16, 0.16016448969609);
    effector:SetKey(_TRACK_A, 8.76, 0.33783246922428);
    effector:SetKey(_TRACK_A, 9.32, 0.41421507779883);

    effector:Play();


    -- Layer Crab1
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/Crab_[0000-0007].png');
    element:SetName('Crab1');
    compositionEnvFront:AddElement(element);
    element:SetHotSpot(51, 42.5);
    element:SetParentElement(compositionEnvFront);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_X, 0, 720.5);
    effector:SetKey(_TRACK_Y, 0, 793);
    effector:SetKey(_TRACK_X, 0.489296875, 688.5);
    effector:SetKey(_TRACK_Y, 0.489296875, 746.5);
    effector:SetKey(_TRACK_X, 0.8562890625, 678.5);
    effector:SetKey(_TRACK_Y, 0.8562890625, 709);
    effector:SetKey(_TRACK_X, 1.2844140625, 637.5);
    effector:SetKey(_TRACK_Y, 1.2844140625, 696.5);
    effector:SetKey(_TRACK_X, 1.7737109375, 599);
    effector:SetKey(_TRACK_Y, 1.7737109375, 688.5);
    effector:SetKey(_TRACK_X, 2.3853515625, 573);
    effector:SetKey(_TRACK_Y, 2.3853515625, 685.5);
    effector:SetKey(_TRACK_X, 2.75234375, 604);
    effector:SetKey(_TRACK_Y, 2.75234375, 675.5);
    effector:SetKey(_TRACK_X, 3.18046875, 630);
    effector:SetKey(_TRACK_Y, 3.18046875, 657);
    effector:SetKey(_TRACK_X, 3.5474609375, 659.5);
    effector:SetKey(_TRACK_Y, 3.5474609375, 646.5);
    effector:SetKey(_TRACK_X, 4.0367578125, 678);
    effector:SetKey(_TRACK_Y, 4.0367578125, 629.5);
    effector:SetKey(_TRACK_X, 4.4, 696.5);
    effector:SetKey(_TRACK_Y, 4.4, 624);
    effector:SetKey(_TRACK_X, 5.04, 740);
    effector:SetKey(_TRACK_Y, 5.04, 622);
    effector:SetKey(_TRACK_X, 5.56, 773.5);
    effector:SetKey(_TRACK_Y, 5.56, 624.5);
    effector:SetKey(_TRACK_X, 5.92, 818.5);
    effector:SetKey(_TRACK_Y, 5.92, 625.5);
    effector:SetKey(_TRACK_X, 6.2, 864.5);
    effector:SetKey(_TRACK_Y, 6.2, 623);
    effector:SetKey(_TRACK_X, 6.56, 895);
    effector:SetKey(_TRACK_Y, 6.56, 621.5);
    effector:SetKey(_TRACK_X, 6.96, 921.5);
    effector:SetKey(_TRACK_Y, 6.96, 620);
    effector:SetKey(_TRACK_X, 7.4, 954);
    effector:SetKey(_TRACK_Y, 7.4, 614.5);
    effector:SetKey(_TRACK_X, 7.76, 946);
    effector:SetKey(_TRACK_Y, 7.76, 613.5);
    effector:SetKey(_TRACK_X, 7.88, 945.5);
    effector:SetKey(_TRACK_Y, 7.88, 613.25);
    effector:SetKey(_TRACK_X, 8.12, 938.125);
    effector:SetKey(_TRACK_Y, 8.12, 609.125);
    effector:SetKey(_TRACK_X, 8.36, 925.5);
    effector:SetKey(_TRACK_Y, 8.36, 588.5);
    effector:SetKey(_TRACK_X, 8.6, 917.75);
    effector:SetKey(_TRACK_Y, 8.6, 572.75);
    effector:SetKey(_TRACK_X, 8.84, 913);
    effector:SetKey(_TRACK_Y, 8.84, 570.5);
    effector:SetKey(_TRACK_X, 9.2, 893.75);
    effector:SetKey(_TRACK_Y, 9.2, 577);
    effector:SetKey(_TRACK_X, 9.52, 870.75);
    effector:SetKey(_TRACK_Y, 9.52, 583.75);
    effector:SetKey(_TRACK_X, 9.88, 833.25);
    effector:SetKey(_TRACK_Y, 9.88, 594.75);
    effector:SetKey(_TRACK_SX, 0, 0.6);
    effector:SetKey(_TRACK_SY, 0, 0.6);
    effector:SetKey(_TRACK_SX, 1.9572265625, 0.5);
    effector:SetKey(_TRACK_SY, 1.9572265625, 0.5);
    effector:SetKey(_TRACK_SX, 3.5474609375, 0.4);
    effector:SetKey(_TRACK_SY, 3.5474609375, 0.4);
    effector:SetKey(_TRACK_SX, 6.56, 0.3);
    effector:SetKey(_TRACK_SY, 6.56, 0.3);
    effector:SetKey(_TRACK_SX, 7.4, 0.25);
    effector:SetKey(_TRACK_SY, 7.4, 0.25);
    effector:SetKey(_TRACK_SX, 7.76, 0.25);
    effector:SetKey(_TRACK_SY, 7.76, 0.25);
    effector:SetKey(_TRACK_A, 0, 0);
    effector:SetKey(_TRACK_A, 0.428125, 0.42558717808917);
    effector:SetKey(_TRACK_A, 0.6728125, 0.29436672336436);
    effector:SetKey(_TRACK_A, 1.162109375, 0.0539988598518);
    effector:SetKey(_TRACK_A, 2.3853515625, -0.14812107406673);
    effector:SetKey(_TRACK_A, 4.0367578125, -0.4527304499767);
    effector:SetKey(_TRACK_A, 4.4, 0.09249670493756);
    effector:SetKey(_TRACK_A, 6.96, -0.15055764983137);
    effector:SetKey(_TRACK_A, 7.4, 0.04683790979295);
    effector:SetKey(_TRACK_A, 7.76, 0.04683790979295);
    effector:SetKey(_TRACK_A, 7.88, 0.16226457002798);
    effector:SetKey(_TRACK_A, 8.12, 0.78503745246663);
    effector:SetKey(_TRACK_A, 8.36, 1.13672306871384);
    effector:SetKey(_TRACK_A, 8.6, 1.07531754373735);
    effector:SetKey(_TRACK_A, 8.84, -0.18726682702158);
    effector:SetKey(_TRACK_O, 0, 1);
    effector:SetKey(_TRACK_O, 4.56, 1);
    effector:SetKey(_TRACK_O, 4.64, 0);
    effector:SetKey(_TRACK_O, 6.32, 0);
    effector:SetKey(_TRACK_O, 6.4, 0.8);
    effector:SetKey(_TRACK_O, 9.68, 0.8);
    effector:SetKey(_TRACK_O, 9.76, 0);

    effector:Play();

    compositionEnvFront:Play();

    return compositionEnvFront;
end

createCompositionWaves = function()

    local compositionWaves = CreateCompositionSequence();
    local compositionDuration = 2.8;
    compositionWaves:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave1_01.png');
    element:SetName('Layer_1');
    compositionWaves:AddElement(element);
    element:SetHotSpot(30, 30);
    element:SetParentElement(compositionWaves);
    element:SetAngle(0.0764523222688);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.8);

    effector:SetKey(_TRACK_X, 0, 60.5484161376953);
    effector:SetKey(_TRACK_Y, 0, 48.0067596435547);
    effector:SetKey(_TRACK_X, 0.4, 54.297637106958);
    effector:SetKey(_TRACK_Y, 0.4, 47.2984303052508);
    effector:SetKey(_TRACK_X, 0.84, 45.1377213903745);
    effector:SetKey(_TRACK_Y, 0.84, 45.9691954245113);
    effector:SetKey(_TRACK_X, 1.2, 37.5834910994045);
    effector:SetKey(_TRACK_Y, 1.2, 46.1192187218134);
    effector:SetKey(_TRACK_X, 1.32, 35.4234161376953);
    effector:SetKey(_TRACK_Y, 1.32, 46.7567596435547);
    effector:SetKey(_TRACK_X, 1.48, 34.8158100926364);
    effector:SetKey(_TRACK_Y, 1.48, 47.6102043175448);
    effector:SetKey(_TRACK_X, 1.68, 37.2240347193645);
    effector:SetKey(_TRACK_Y, 1.68, 48.5125118914486);
    effector:SetKey(_TRACK_X, 2, 42.2984161376953);
    effector:SetKey(_TRACK_Y, 2, 49.7567596435547);
    effector:SetKey(_TRACK_X, 2.56, 54.1734161376953);
    effector:SetKey(_TRACK_Y, 2.56, 49.5067596435547);
    effector:SetKey(_TRACK_SX, 0, 1);
    effector:SetKey(_TRACK_SY, 0, 0.84166666666667);
    effector:SetKey(_TRACK_SX, 1.2, 1.2002666598785);
    effector:SetKey(_TRACK_SY, 1.2, 1.69616072685029);
    effector:SetKey(_TRACK_SX, 1.84, 1.33827271567605);
    effector:SetKey(_TRACK_SY, 1.84, 1.91151934120104);
    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 1.32, 0.8);
    effector:SetKey(_TRACK_O, 2, 0);

    effector:Play();

    compositionWaves:Play();

    return compositionWaves;
end

createCompositionWaves2 = function()

    local compositionWaves2 = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionWaves2:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_1');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(310.873870849609, 544.531539916992);

    element:SetScaleX(-0.72);
    element:SetScaleY(0.9047619047619);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0, 0.8);
    effector:SetKey(_TRACK_O, 1.84, 0);
    effector:SetKey(_TRACK_O, 4.28, 0);
    effector:SetKey(_TRACK_O, 5.72, 0.8);
    effector:SetKey(_TRACK_O, 7.56, 0);
    effector:SetKey(_TRACK_O, 9.36, 0);
    effector:SetKey(_TRACK_O, 9.92, 0.8);

    effector:Play();


    -- Layer Layer_2
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_2');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(369.873870849609, 495.531539916992);

    element:SetScaleX(-1.12);
    element:SetScaleY(0.33333333333333);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0, 0.8);
    effector:SetKey(_TRACK_O, 1.8, 0);
    effector:SetKey(_TRACK_O, 4.24, 0);
    effector:SetKey(_TRACK_O, 5.68, 0.8);
    effector:SetKey(_TRACK_O, 7.52, 0);
    effector:SetKey(_TRACK_O, 9.32, 0);
    effector:SetKey(_TRACK_O, 9.92, 0.8);

    effector:Play();


    -- Layer Layer_3
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_3');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(338.873870849609, 534.531539916992);

    element:SetScaleX(-1.1);
    element:SetScaleY(0.61904761904762);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0.84, 0);
    effector:SetKey(_TRACK_O, 2.28, 0.8);
    effector:SetKey(_TRACK_O, 4.12, 0);
    effector:SetKey(_TRACK_O, 6.56, 0);
    effector:SetKey(_TRACK_O, 8, 0.8);
    effector:SetKey(_TRACK_O, 9.84, 0);

    effector:Play();


    -- Layer Layer_4
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_4');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(382.873870849609, 515.531539916992);

    element:SetScaleX(1.18);
    element:SetScaleY(0.47619047619048);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0.28, 0);
    effector:SetKey(_TRACK_O, 1.72, 0.8);
    effector:SetKey(_TRACK_O, 3.56, 0);
    effector:SetKey(_TRACK_O, 6, 0);
    effector:SetKey(_TRACK_O, 7.44, 0.8);
    effector:SetKey(_TRACK_O, 9.28, 0);

    effector:Play();


    -- Layer Layer_5
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_5');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(566.873870849609, 561.531539916992);

    element:SetScaleX(1.06);
    element:SetScaleY(1.04761904761905);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0.52, 0);
    effector:SetKey(_TRACK_O, 1.96, 0.8);
    effector:SetKey(_TRACK_O, 3.8, 0);
    effector:SetKey(_TRACK_O, 6.24, 0);
    effector:SetKey(_TRACK_O, 7.68, 0.8);
    effector:SetKey(_TRACK_O, 9.52, 0);

    effector:Play();


    -- Layer Layer_6
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_6');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(478.873870849609, 502.531539916992);

    element:SetScaleX(0.94);
    element:SetScaleY(1.14285714285714);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 1.44, 0.8);
    effector:SetKey(_TRACK_O, 3.28, 0);
    effector:SetKey(_TRACK_O, 5.72, 0);
    effector:SetKey(_TRACK_O, 7.16, 0.8);
    effector:SetKey(_TRACK_O, 9, 0);

    effector:Play();


    -- Layer Layer_7
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_7');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(470.873870849609, 396.031539916992);

    element:SetScaleX(0.4);
    element:SetScaleY(0.76190476190476);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 2.08, 0);
    effector:SetKey(_TRACK_O, 3.52, 0.8);
    effector:SetKey(_TRACK_O, 5.36, 0);
    effector:SetKey(_TRACK_O, 6.64, 0);
    effector:SetKey(_TRACK_O, 8.08, 0.8);
    effector:SetKey(_TRACK_O, 9.92, 0);

    effector:Play();


    -- Layer Layer_8
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_8');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(463.873870849609, 374.031539916992);

    element:SetScaleX(0.53);
    element:SetScaleY(0.57142857142857);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 1.12, 0);
    effector:SetKey(_TRACK_O, 2.56, 0.8);
    effector:SetKey(_TRACK_O, 4.4, 0);
    effector:SetKey(_TRACK_O, 6.64, 0);
    effector:SetKey(_TRACK_O, 8.08, 0.8);
    effector:SetKey(_TRACK_O, 9.92, 0);

    effector:Play();


    -- Layer Layer_9
    local element = auxCreateCompositionElement('data/Texture/Scenes/20_NearCollapsedShip/Animations/Env/EF_wave2_01.png');
    element:SetName('Layer_9');
    compositionWaves2:AddElement(element);
    element:SetHotSpot(50, 21);
    element:SetParentElement(compositionWaves2);
    element:SetXY(469.873870849609, 345.531539916992);

    element:SetScaleX(0.32);
    element:SetScaleY(0.76190476190476);
    element:SetAngle(0);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 10);

    effector:SetKey(_TRACK_O, 0, 0);
    effector:SetKey(_TRACK_O, 1.44, 0.8);
    effector:SetKey(_TRACK_O, 3.28, 0);
    effector:SetKey(_TRACK_O, 5.72, 0);
    effector:SetKey(_TRACK_O, 7.16, 0.8);
    effector:SetKey(_TRACK_O, 9, 0);

    effector:Play();

    compositionWaves2:Play();

    return compositionWaves2;
end

createCompositionWavesAll = function()

    local compositionWavesAll = CreateCompositionSequence();
    local compositionDuration = 10;
    compositionWavesAll:SetDuration(compositionDuration);


    -- Layer Layer_1
    local element = createCompositionWaves();
    element:SetName('Layer_1');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(310.198196411133, 547.747741699219);

    element:SetScaleX(1.16816816816817);
    element:SetScaleY(0.85585585585586);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(7.04, 9.84);


    effector:Play();


    -- Layer Layer_2
    local element = createCompositionWaves();
    element:SetName('Layer_2');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(340.18017578125, 510.84684753418);

    element:SetScaleX(1.02402402402402);
    element:SetScaleY(-0.68168168168168);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(6.44, 9.24);


    effector:Play();


    -- Layer Layer_3
    local element = createCompositionWaves();
    element:SetName('Layer_3');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(370.162155151367, 497.009002685547);

    element:SetScaleX(1);
    element:SetScaleY(0.54354354354354);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(6.2, 9);


    effector:Play();


    -- Layer Layer_4
    local element = createCompositionWaves();
    element:SetName('Layer_4');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(318.270263671875, 543.135131835938);

    element:SetScaleX(1.12012012012012);
    element:SetScaleY(0.83183183183183);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(3.92, 6.72);


    effector:Play();


    -- Layer Layer_5
    local element = createCompositionWaves();
    element:SetName('Layer_5');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(349.405410766602, 509.693695068359);

    element:SetScaleX(1.0960960960961);
    element:SetScaleY(-0.56156156156156);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(3.32, 6.12);


    effector:Play();


    -- Layer Layer_6
    local element = createCompositionWaves();
    element:SetName('Layer_6');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(363.243240356445, 492.396392822266);

    element:SetScaleX(0.95195195195195);
    element:SetScaleY(0.51951951951952);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(3.08, 5.88);


    effector:Play();


    -- Layer Layer_7
    local element = createCompositionWaves();
    element:SetName('Layer_7');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(313.657653808594, 537.369369506836);

    element:SetScaleX(1.0960960960961);
    element:SetScaleY(0.78378378378378);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0.84, 3.64);


    effector:Play();


    -- Layer Layer_8
    local element = createCompositionWaves();
    element:SetName('Layer_8');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(335.567565917969, 517.765762329102);

    element:SetScaleX(1);
    element:SetScaleY(-0.56156156156156);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0.24, 3.04);


    effector:Play();


    -- Layer Layer_9
    local element = createCompositionWaves();
    element:SetName('Layer_9');
    compositionWavesAll:AddElement(element);
    element:SetHotSpot(48, 48);
    element:SetParentElement(compositionWavesAll);
    element:SetXY(363.243240356445, 492.396392822266);

    element:SetScaleX(1);
    element:SetScaleY(0.47147147147147);
    element:SetAngle(0);
    element:SetOpacity(1);

    effector = element:GetEffector();
    effector:SetLifeTime(0, 2.8);


    effector:Play();

    compositionWavesAll:Play();

    return compositionWavesAll;
end

