def runlevel(levelslevelnum) global currentimage levelobj levels[levelnum mapobj decoratemap(levelobj['mapobj']levelobj['startstate']['player'] gamestateobj copy deepcopy(levelobj['startstate']the levels list contains all the level objects that were loaded from the level file the level object for the current level (which is what levelnum is set tois stored in the levelobj variable map object (which makes distinction between indoor and outdoor tilesand decorates the outdoor tiles with trees and rocksis returned from the decoratemap(function and to track the state of the game while the player plays this levela copy of the game state object that is stored in levelobj is made using the copy deepcopy(function the game state object copy is made because the game state object stored in levelobj['startstate'represents the game state at the very beginning of the leveland we do not want to modify this otherwiseif the player restarts the levelthe original game state for that level will be lost the copy deepcopy(function is used because the game state object is dictionary of that has tuples but technicallythe dictionary contains references to tuples (references are explained in detail at dictionary will make copy of the references but not the values they refer toso that both the copy and the original dictionary still refer to the same tuples the copy deepcopy(function solves this problem by making copies of the actual tuples in the dictionary this way we can guarantee that changing one dictionary will not affect the other dictionary mapneedsredraw true set to true to call drawmap( levelsurf basicfont render('level % of % (levelobj['levelnum' totalnumoflevels) textcolor levelrect levelsurf get_rect( levelrect bottomleft ( winheight mapwidth len(mapobjtilewidth mapheight (len(mapobj[ ] (tileheight tilefloorheighttileheight max_cam_x_pan abs(half_winheight int(mapheight )tilewidth max_cam_y_pan abs(half_winwidth int(mapwidth )tileheight leveliscomplete false track how much the camera has moved cameraoffsetx