Example #1
0
class GameManager:
    currentLevel = Level(0)
    texture = Texture()

    def __init__(self):
        self.display = Display(self, (const.WIN_WIDTH, const.WIN_HEIGHT))
        self.player = Player(self)

    def getTexture(self):
        return self.texture

    def getDisplay(self):
        return self.display

    def getPlayer(self):
        return self.player

    def getCurrentLevel(self):
        return self.currentLevel

    def setCurrentLevel(self, _lv):
        self.currentLevel = _lv

    def start(self, _lv):
        self.setCurrentLevel(Level(_lv))
        loc = self.getCurrentLevel().getStarting()
        loc = loc.addVec(
            Vector((50 - const.CHAR_WIDTH) / 2, -const.CHAR_HEIGHT))
        self.getPlayer().setLocation(loc)
Example #2
0
    def data_gen(self):
        """ Instancy all the necessaries classes """

        self.data = {
            "menu": MainMenu(),
            "audio": Audio(),
            "level": Level(),
            "map": LevelDisplay(),
            "inventory": InventoryDisplay(),
            "win": Win(),
            "go": GameOver()
        }
Example #3
0
 def start(self, _lv):
     self.setCurrentLevel(Level(_lv))
     loc = self.getCurrentLevel().getStarting()
     loc = loc.addVec(
         Vector((50 - const.CHAR_WIDTH) / 2, -const.CHAR_HEIGHT))
     self.getPlayer().setLocation(loc)
Example #4
0
from audio.audio_config import pick_up_sound
from display.main_menu import Main_menu
from classes.level import Level
from display.inventory_display import InventoryDisplay
from display.level_display import LevelDisplay


pygame.init()

# Creating the display 600x600 pixels
res = (640, 600)
pygame.display.set_caption("Help Macgyver to escape")
screen = pygame.display.set_mode(res)


level = Level()
main_menu_dis = Main_menu()
level_dis = LevelDisplay()
inventory_dis = InventoryDisplay()

pygame.mixer.init()
pygame.mixer.music.load(menu_music)
pygame.mixer.music.play(-1)

#creating a for loop to keep the game game_running
game_running = False
main_menu_running = True
while main_menu_running:
    
    screen.blit(main_menu_dis.background, (0, 0))
    screen.blit(main_menu_dis.play_button,(main_menu_dis.play_button_rect))
Example #5
0
def display_level(numLevel, window):
    """Display the level of the game"""

    #Method variables
    quit_game = False
    keep_playing = True
    levelRestart = True
    playerWin = bool()
    gameStatus = dict()

    while levelRestart:
        #While the level is not over
        #Displaying the level
        level = Level(numLevel)
        print("Loading level : " + str(level.numLevel))
        keep_playing = True
        level.set_tiles_on_screen(window, len(level._get_CSV_Grid()),
                                  len(level._get_CSV_Grid()[0]))
        level.set_elements_on_screen(window)
        pygame.display.flip()

        while keep_playing:

            for event in pygame.event.get():
                if event.type == KEYDOWN and (event.key == K_LEFT or event.key
                                              == K_RIGHT or event.key == K_DOWN
                                              or event.key == K_UP):
                    nextPlayerPosition = eventHandler.player_movement(
                        event, level)

                    if nextPlayerPosition is not None:
                        movementIsValid = level.check_if_movement_is_valid(
                            nextPlayerPosition)

                        if movementIsValid:
                            level.check_if_player_is_on_element(
                                nextPlayerPosition)
                            playerWin = level.check_if_player_is_on_guardian(
                                nextPlayerPosition)

                            if playerWin is None:
                                level.move_player(nextPlayerPosition)

                            elif playerWin == True:
                                print("Player wins.")
                                keep_playing = False
                                levelRestart = False

                            else:
                                print("Player loses")
                                keep_playing = False
                                levelRestart = False

                            level.set_tiles_on_screen(
                                window, len(level._get_CSV_Grid()),
                                len(level._get_CSV_Grid()[0]))
                            level.set_elements_on_screen(window)
                            pygame.display.flip()

                        print("--------- End of turn ---------")

                elif event.type == QUIT:
                    print("Goodbye")
                    keep_playing = False  #We exit the cycle where we listen for events
                    quit_game = True  #We exit the cycle of the game
                    levelRestart = False

    gameStatus = {"quit_game": quit_game, "playerWin": playerWin}

    return gameStatus
Example #6
0
def displayLevel(numLevel, window):
    """Display the level of the game"""

    #Method variables
    quit_game = False
    keep_playing = True
    levelRestart = True
    playerWin = bool()

    #background = pygame.image.load("resources/img/fond.jpg").convert()
    #window.blit(background, (0,0))
    #pygame.display.flip()

    while levelRestart:
        #While the level is not over
        #Displaying the level
        level = Level(numLevel)
        print("Loading level : " + str(level.numLevel))
        keep_playing = True
        level.setTilesOnScreen(window, len(level._get_CSV_Grid()),
                               len(level._get_CSV_Grid()[0]))
        level.setElementsOnScreen(window)

        while keep_playing:

            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    nextPlayerPosition = eventHandler.playerMovement(
                        event, level)

                    if nextPlayerPosition is not None:
                        movementIsValid = level.checkIfMovementIsValid(
                            nextPlayerPosition)

                        if movementIsValid:
                            level.checkIfPlayerIsOnElement(nextPlayerPosition)
                            playerWin = level.checkIfPlayerIsOnGuardian(
                                nextPlayerPosition)

                            if playerWin is None:
                                level.movePlayer(nextPlayerPosition)

                            elif playerWin == True:
                                print("Player wins.")
                                keep_playing = False
                                levelRestart = False

                            else:
                                keep_playing = False
                                levelRestart = True

                            #Displaying the level
                            level.setTilesOnScreen(
                                window, len(level._get_CSV_Grid()),
                                len(level._get_CSV_Grid()[0]))
                            level.setElementsOnScreen(window)
                        print("--------- End of turn ---------")

                elif event.type == QUIT:
                    print("Goodbye")
                    keep_playing = False  #We exit the cycle where we listen for events
                    quit_game = True  #We exit the cycle of the game
                    levelRestart = False

    return quit_game
Example #7
0
def displayLevel(numLevel, window):
    """Display the level the player has selected """
    print("Chargement du niveau " + str(numLevel))
    loadLevel = True

    #While we need to reload the same level (for restart or a death for example)
    #We reload it
    while loadLevel == True:
        #String that will go back to main and let the program knows what to do next
        #Go to next level? Quit the game?
        action = ""

        #We create the object Level and load its elements
        level = Level(numLevel)

        #If it couldn't find a level in levelFile, it means the game is finished and
        #we display the title screen
        if level.csvPath is None:
            return "Title_Screen"
        else:
            level.loadingLevelForDisplay()

        #We calculate where should be the center of the game on the screen in order
        #to display correctly all elements
        gameWidth = len(level._get_grille()[0]) * 30
        firstPixel = centerTheGameOnTheScreen(window.get_width(), gameWidth)

        #We set a new background image
        window.fill(pygame.Color("black"))
        background = pygame.image.load("resources/img/fond.jpg").convert()
        window.blit(background, (firstPixel, 0))
        pygame.display.flip()

        #We place each element with their pixels position on the screen
        displayGrille(level, firstPixel, window)

        #We place the player on the table
        player = Player()
        playerPNG = pygame.image.load(player.character.skin).convert_alpha()
        player.positionRect = playerPNG.get_rect(x=level.start[0],
                                                 y=level.start[1])

        window.blit(playerPNG, (firstPixel + player.positionRect.x * 30,
                                player.positionRect.y * 30))
        pygame.display.flip()

        continuer = 1

        #We display the level while the player hasn't finished it
        while continuer:

            #We display background and elements of the level again
            window.fill(pygame.Color("Black"))

            #We load the background image
            window.blit(background, (firstPixel, 0))

            #We load the table of elements with their graphics
            displayGrille(level, firstPixel, window)

            #We load the player character (donkey kong)
            playerPNG = pygame.image.load(
                player.character.skin).convert_alpha()
            window.blit(playerPNG, (firstPixel + player.positionRect.x * 30,
                                    player.positionRect.y * 30))

            #If the player walked on a scroll, we display its message
            level.checkPlayerOnScroll(player, window)

            pygame.display.flip()

            for event in pygame.event.get():
                if event.type == QUIT:
                    action = "Quit_the_game"
                    loadLevel = False
                    continuer = 0

                #If the player presses a key, we check if he can move
                elif event.type == KEYDOWN:
                    if event.key == K_r:
                        continuer = 0
                    elif event.key == K_LEFT or event.key == K_RIGHT or event.key == K_UP or event.key == K_DOWN:
                        #If the player will move on a cell where there is a box
                        potentialBox = level.checkPlayerBoxes(player, event)
                        if potentialBox is not None:
                            box = potentialBox
                            if box.canMove(player, level, event):
                                player.move(level, event)

                        else:
                            player.move(level, event)

                    #If the player dies, he goes back to the starting point of the current level
                    if level.checkPlayerDies(player):
                        continuer = 0

                    #If player walks on the finish line, he goes to next level
                    if level.checkEndLevel(player):
                        continuer = 0
                        loadLevel = False
                        action = "Next_level"

    return action