--------------------------------------------------------------------------------
function MakeSoundEntity(soundName)

    local result = CreateSoundEntity(soundName);
    result:AttachTo(play_field);
    return result;

end

--------------------------------------------------------------------------------
currentMusicTrack = nil;
previousMusicTrack = nil;
--------------------------------------------------------------------------------
function PlayAmbientMusic(musicTrack, fade)

    if (currentMusicTrack ~= musicTrack)
    then
        if (currentMusicTrack)
        then
            StopMusic(currentMusicTrack, fade or false);
        end
        
        currentMusicTrack = musicTrack;
        
        if (currentMusicTrack)
        then
            PlayMusic(currentMusicTrack, fade or false);
        end
    end

end

--------------------------------------------------------------------------------
function StopAmbientMusic(fade)
    PlayAmbientMusic(nil, fade);
end

--------------------------------------------------------------------------------
function PauseAmbientMusic(fade)
    previousMusicTrack = currentMusicTrack;
    StopAmbientMusic(fade);
end

--------------------------------------------------------------------------------
function ContinueAmbientMusic(fade)

    if (currentMusicTrack == nil and previousMusicTrack ~= nil)
    then
        PlayAmbientMusic(previousMusicTrack, fade);
        previousMusicTrack = nil;
    end
    
end

--------------------------------------------------------------------------------
function PlayRandomAmbientMusic()

    local musicTrack = SelectRandom("music1", "music2", "music3");
    PlayAmbientMusic(musicTrack, true);
    
end

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