use a 2d array
position 0,1 = level 1
position 0,2 = level 2
etc..
When you collect a star on a level add a value of 1 to the corrisponding array position and to get the total amount throughout all levels just add up all the array values and set your global variable to it.