to better understand how the floodfill(function workshere is version that does not use recursive callsbut instead uses list of xy coordinates to keep track of which spaces on the map should be checked and possibly changed to newcharacter def floodfill(mapobjxyoldcharacternewcharacter)spacestocheck [if mapobj[ ][ =oldcharacterspacestocheck append((xy)while spacestocheck ![]xy spacestocheck pop(mapobj[ ][ynewcharacter if len(mapobj and mapobj[ + ][ =oldcharacterspacestocheck append(( + )check right if and mapobj[ - ][ =oldcharacterspacestocheck append(( - )check left if len(mapobj[ ] and mapobj[ ][ + =oldcharacterspacestocheck append((xy+ )check down if and mapobj[ ][ - =oldcharacterspacestocheck append((xy- )check up if you would like to read more detailed tutorial on recursion that uses cats and zombies for an examplego to drawing the map def drawmap(mapobjgamestateobjgoals) """draws the map to surface objectincluding the player and stars this function does not call pygame display update()nor does it draw the "leveland "stepstext in the corner "" mapsurf will be the single surface object that the tiles are drawn onso that it is easy to position the entire map on the displaysurf surface object firstthe width and height must be calculated mapsurfwidth len(mapobjtilewidth mapsurfheight (len(mapobj[ ] (tileheight tilefloorheighttileheight mapsurf pygame surface((mapsurfwidthmapsurfheight) mapsurf fill(bgcolorstart with blank color on the surface the drawmap(function will return surface object with the entire map (and the player and starsdrawn on it the width and height needed for this surface have to be calculated from mapobj (which is done on line and the surface object that everything will be drawn