All episodes have two to four generators that need to be turned on to free the bear, who you need to bring to the next episode door in dungeon to unlock the next episode.
To turn on a generator, you must follow the solid white lines from the chest near the entrance and complete all the levels that sit on the white line. When you have completed the levels on a while line, you can press the red button that turns on the generator, and it will transport you back to the chest in the beginning of the episode.
When there are no more mandatory levels left, and all the generators have been turned on, you can open the chest and collect a bear friend. To proceed to the next episode, return to the dungeon while the bear sits on your head and go to the next set of elevator doors. The bear will jump off, open the door for you and you are ready for the next episode.
The levels on the dashed lines are optional and you don't need to complete those in order to get closer to turning on the generators. The community levels are also optional. You don't need to complete the episode 100%.