import pygame, sys, wall, playerfrom pygame.locals import *from

import pygame, sys, wall, playerfrom pygame.locals import *from levels import *# initialize pygamepygame.init()# define intial variables to be passed in as arguments to functions and classessize = 400col = FalsecurrentLevel = 0maxLevel = 7# set up screen instancescreen = pygame.display.set_mode((size, size))pygame.display.set_caption(“ManMaze: The Hunt for Costco Pizza: – %s” % str(currentLevel + 1))# creates allotment of groups (from sprite.Sprite) to have special access to the group functionslevel1List = pygame.sprite.Group()level2List = pygame.sprite.Group()level3List = pygame.sprite.Group()level4List = pygame.sprite.Group()level5List = pygame.sprite.Group()level6List = pygame.sprite.Group()level7List = pygame.sprite.Group()wallList = pygame.sprite.Group()playerList = pygame.sprite.Group()  # 1 of 2 of ‘ultimate’ listssmallList = pygame.sprite.Group()   # small player (level 6 and up)bigList = pygame.sprite.Group()     # big player (level(s) 1 through 5)allSprites = pygame.sprite.Group()  # 2 of 2 of ‘ultimate’ lists# create a parallel array group of a list of lists.levels = level1, level2, level3, level4, level5, level6, level7levelLists = level1List, level2List, level3List, level4List, level5List, level6List, level7Listdef setup(level, levelList, current):    for i in range(len(level)):        for j in range(len(leveli)):            if levelij == 1:                if current <= 4:   # iterate over each "comp%j" component (of the levels list)...ex. = comp0,comp1,comp2...                    # mapping for maps 1 through 4 (larger rendering)                    globals()"comp%s" % j = wall.Wall(20, 20)   # creates individual instance of wall; arg = width and height                    globals()"comp%s" % j.rect.x = j * 20       # init x-position, first would be 0, second would be 20, so on...                    globals()"comp%s" % j.rect.y = i * 20       # init y-position, "      "       "       "       "       "                else:                    # mapping for maps 5 through 7 (smaller rendering)                    globals()"comp%s" % j = wall.Wall(10, 10)                    globals()"comp%s" % j.rect.x = j * 10                    globals()"comp%s" % j.rect.y = i * 10                # once finished with one j iteration; add them to groups for group function capability                levelList.add(globals()"comp%s" % j)                wallList.add(globals()"comp%s" % j)                allSprites.add(globals()"comp%s" % j)# big player declarationsbigPlayer = player.Player(col, 10)bigPlayer.rect.x = 20bigPlayer.rect.y = 20bigList.add(bigPlayer)# small player declarationssmallPlayer = player.Player(col, 5)smallPlayer.rect.x = 10smallPlayer.rect.y = 10smallList.add(smallPlayer)# add both to ultimate lists (where both can exist)playerList.add(bigPlayer, smallPlayer)allSprites.add(bigPlayer, smallPlayer)# using the setup() function; this loop creates the map of each levelfor i in range(maxLevel):    setup(levelsi, levelListsi, i)# define pygame clockclock = pygame.time.Clock()timer = 0font = pygame.font.Font("imagine_font.ttf", 12)# collision check function; if player keeps running into wall; function counter acts in opposite directiondef colCheck(player):    if col != :  # if col doesn't equal null (if there is collision)        if player.direction == 1:            player.rect.x += player.speed  # 1 in the player class represents left, so this makes it go right temporarily        elif player.direction == 2:            player.rect.y += player.speed  # 2 "  "   "      "     "          right, "   "   "    "   "  left  "...        elif player.direction == 3:            player.rect.x -= player.speed  # and so on...        elif player.direction == 4:            player.rect.y -= player.speed# end of level verification; when the user passes by the end def checkEnd(player, start, end):    global currentLevel   # updates outside of funtion for obvious reasons    if player.rect.x > end and player.rect.y > end:   # if the x and y coordinates are past the end        player.rect.x = start        player.rect.y = start   # place both of them back at starting positon        if currentLevel < maxLevel:   # switches the caption at the top of the screen; increments current level            currentLevel += 1            pygame.display.set_caption("ManMaze: The Hunt for Costco Pizza: - %s" % str(currentLevel + 1))while True:    keys = pygame.key.get_pressed()    screen.fill((225, 222, 173))    # creates instance of spritecollide, with bigPlayer SPRITE and levelList GROUP; dokill = FALSE so wall is not removed from list.    if currentLevel <= 4:        col = pygame.sprite.spritecollide(bigPlayer, levelListscurrentLevel, False)        colCheck(bigPlayer)   # implements this so that the user cant go through the wall                bigList.draw(screen)   # draws player to screen (over screen)        bigPlayer.keyDown(keys)   # checks if keys are being pressed; if so, moves player        checkEnd(bigPlayer, 20, 360)   # end for big - 360x360 (bottom right), short is 20x20 (top left)    else:        col = pygame.sprite.spritecollide(smallPlayer, levelListscurrentLevel, False)        colCheck(smallPlayer)        smallList.draw(screen)        smallPlayer.keyDown(keys)        checkEnd(smallPlayer, 20, 380)   # end for small - 380x380 (bottom right)    # draws the current level map, checkEnd will update the currentLevel variable    levelListscurrentLevel.draw(screen)    timerBlit = font.render("Time: " + str(timer // 60), 1, (255, 0, 0)) # game is run in 60 FPS, timer //  60 will give each second    screen.blit(timerBlit, (1,1))    timer +=1    # generic event quit function    for event in pygame.event.get():        if event.type == QUIT:            pygame.quit()            sys.exit()    clock.tick(60)    pygame.display.update()

Written by