You have to break (touch) the rope at the level's exit to earn stars. The higher it is when you break it, the more stars you get — up to 50. Getting all 50 gets you three bonus extra lives.
The white horizontal bar between the two vertical striped bars is the 'rope' to which I refer.
Once you have acquired 100 red stars, you enter a bonus game where you can earn extra lives.
The minigame starts with 8 squares that had changing icons on them (the one in center does not change). The 8 squares around the center rotate around the middle square. The objective is to hit the moving squares to make them stop changing their icons. Once you are done, you get an extra life for every row of similar icons.
Unfortunately there is no pattern. The box that contains the 1up is assigned randomly to one of the three on that tier and doesn't change the location of other 1ups on that bonus level.
However, there is a method to con the boxes into being "the right one", be it a glitch or otherwise. This method involves hitting the corner of a box with your cape (while spin jumping), but without jumping too high and making it into the next section.
Edit: Here's a video of someone executing this method:
Best Answer