Example #1
0
        def loadLevelN(level):
            """
            Checks if that level is avaiable to play (the level before it has
            been complete). If that holds True allows to play it.
            Doesn't work for level one.
            @level: of the form 'level1'
            """
            # Level1 is an exception, should be always loaded
            if level == 'level1':
                level = 'levels\\' + level + '.xml'
                WORLD.push(LevelEngine(level).engine)
                # pygame.mixer.music.stop()
                return

            save_file = helper.getSaveFile()
            # Separate letters from numbers
            level_before = ''
            digits = ''
            for char in level:
                if char.isdigit():
                    digits += str(int(char))
                else:
                    level_before += char
            # Substract 1
            digits = str(int(digits)-1)
            # Form the level before
            level_before += digits

            # If the previous level was complete, we allow to load it
            if save_file[level_before]['complete']:
                level = 'levels\\' + level + '.xml'
                WORLD.push(LevelEngine(level).engine)
                # pygame.mixer.music.stop()
            else: #we don't allow it
                print('Can\'t be allowed')
Example #2
0
    def winState(self, position_comp, physics_comp, state_comp, level_info_comp):
        """
        Processes the state when the player wins.
        """
        current_level = level_info_comp.level_name

        # Get next level (add 1 to the number)
        next_level = 'levels\\'
        for char in current_level:
            if char.isdigit():
                next_level += str(int(char)+1)
            else:
                next_level += char

        # Add the xml tag after it
        next_level += '.xml'

        # See if the file exists
        if os.path.isfile(next_level):
            # We load the next level after a brief pause
            def nextLevel():
                pygame.time.wait(250)
                WORLD.change(Engines.LevelEngine(next_level).engine)
            WORLD.addPostUpdateFunction(nextLevel)
        else: # no more levels -> we won
            def winFunction():
                DISPLAYSURF.fill(BLACK)
                helper.outputText('YOU WIN!!',WIN_WIDTH//2, WIN_HEIGHT//2, WHITE,
                                   size = 64, centered=True)
                pygame.display.update()
                pygame.time.wait(1500)
                WORLD.pop()
            WORLD.addPostUpdateFunction(winFunction)

        # print('win', level_info_comp.level_name)

        # Save the info into the save file
        save_file = helper.getSaveFile()
        save_file[current_level]['complete'] = True
        helper.modifySaveFile(save_file)