Example #1
0
def mapCreation(newlevel, x, y, layout):

    # Creates the sprite list
    boxSpriteList = sprite.Group()

    # changes the way the map is generated depending on what kind of map you want
    if (layout).lower() == 'y':
        # For side scrollers
        width = height = intHeight / y
    else:
        # for others
        height = width = intHeight / 20

    # this keeps track of what box it is
    boxnum = 0

    # if is a new map then create it!
    if newlevel == 'y':
        # Go through for every column
        for column in range(y):
            # go through for everything in the row
            for row in range(x):
                # x location
                locx = row * width
                # y location
                locy = column * height
                #creates the box
                box = boxClass.box(width, height, locx, locy, boxnum)
                # adds it to the sprite list
                boxSpriteList.add(box)
                # adds one to the box num
                boxnum += 1

    # Returns the sprites
    return boxSpriteList , width
Example #2
0
def load(sideScroller):


    # gets the map name - must include.txt
    mapName = raw_input('Please enter the name of the map that you would like to load!:')
    # adds .txt to the name
    mapName = mapName + '.txt'
    # Try's to open the map, if it can it'll ask for a new map or if you don't want to load any then it will close
    while True:
        try:
            map = open(mapName, 'r+')
            break
        except:
            mapName = raw_input('No map named %s please try again!:' % mapName)
            mapName = mapName + '.txt'

    # reads the map
    mapString = map.read()
    # closes the file
    map.close()
    # removes ,'s
    mapString = mapString.replace(',', '')
    # splits it at the new line
    mapList = mapString.split('\n')

    # create the box sprite group
    boxSpriteList = pygame.sprite.Group()

    # if its a side scroller it sets the width of the map accordingly
    if sideScroller == 'y':
        width = height = intHeight / len(mapList)
    # if its just a free map then its sets it accordingly
    elif sideScroller == 'n':
        width = height = intHeight / 20

    # this is the num for the box to save again
    boxnum = 0

    # this loop will make the map
    for column in range(len(mapList)):
        for row in range(len(mapList[0])):
                # x location
                locx = row * width
                # y location
                locy = column * height
                #creates the box
                box = boxClass.box(width, height, locx, locy, boxnum)
                # sets the letter of the box
                box.letter = mapList[column][row]
                # this sets the color to black unless you its a ' ' the updates the color
                if box.letter != ' ':
                    box.color = fglobals.colors['black']
                    box.loadUpdate()
                # adds it to the sprite list
                boxSpriteList.add(box)
                # adds one to the box num
                boxnum += 1

    # returns the box sprite list and width
    return boxSpriteList, width
Example #3
0
 if gameStage == 2:
     walls = []
     boxes = []
     goals = []
     holes = []
     telepads = []
     objects = []
     player = None
     debug = False
     levelX = levelY = 0
     for row in levels[level]:
         for col in row:
             if col == "W":
                 walls.append(wallClass.wall(levelX, levelY))
             if col == "B":
                 boxes.append(boxClass.box(levelX, levelY))
             if col == "P":
                 player = playerClass.player(levelX, levelY)
             if col == "G":
                 goals.append(goalClass.goal(levelX, levelY))
             if col == "T":
                 telepads.append(telepadsClass.telepad(levelX, levelY))
             if col == "H":
                 holes.append(holeClass.hole(levelX, levelY))
             levelX += 64
         levelY += 64
         levelX = 0
     objects.append(walls)
     objects.append(holes)
 while gameStage == 2:
     score = 0