Beispiel #1
0
    def on_menu_selection(self, menuitem):
        #if(event.type == "MENU_EVENT"):
        #    if(event.menu_item == "slot one"):
        #        self.selected_index = 0
        #    elif(event.menu_item == "slot two"):
        #        self.selected_index = 1

        try:
            save_data = save.load(self.selected_index + 1)

        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")

        if save_data is not None and "error" not in save_data:
            self.save_data = save.load(self.selected_index + 1)
            self.game.player1 = prepare.player1
            self.game.player1.game_variables = save_data['game_variables']
            self.game.player1.tile_pos = save_data['tile_pos']
            self.game.player1.inventory = save_data['inventory']
            self.game.player1.monsters = save_data['monsters']
            self.game.player1.storage = save_data['storage']
            self.game.player1.name = save_data['player_name']

            old_world = self.game.get_state_name("WorldState")
            if old_world is None:
                # when game is loaded from the start menu
                self.game.pop_state()  # close this menu
                self.game.pop_state()  # close the start menu
            else:
                # when game is loaded from world menu
                self.game.pop_state(self)
                self.game.pop_state(old_world)

            self.game.push_state("WorldState")
            # self.game.current_state.change_map(save_data['current_map'])

            # teleport the player to the correct position using an event engine action
            tele_x = str(int(save_data['tile_pos'][0]))
            tele_y = str(int(save_data['tile_pos'][1]))
            Action = namedtuple("action", ["type", "parameters"])
            action = Action("teleport",
                            [save_data['current_map'], tele_x, tele_y])

            contexts = {}
            self.game.event_engine.actions['teleport']['method'](self.game,
                                                                 action,
                                                                 contexts)
            for key in contexts:
                contexts[key].execute(game)
Beispiel #2
0
    def render_slot(self, rect, slot_num):
        slot_image = pygame.Surface(rect.size, pygame.SRCALPHA)

        # TODO: catch missing file
        thumb_image = pygame.image.load(prepare.SAVE_PATH + str(slot_num) + ".png").convert()
        thumb_rect = thumb_image.get_rect().fit(rect)
        thumb_image = pygame.transform.smoothscale(thumb_image, thumb_rect.size)

        # Draw the screenshot
        slot_image.blit(thumb_image, (rect.width * .20, 0))

        # Draw the slot text
        rect = rect.move(0, rect.height // 2 - 10)
        text.draw_text(slot_image, "Slot " + str(slot_num), rect, font=self.font)

        # Try and load the save game and draw details about the save
        try:
            save_data = save.load(slot_num)
        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")
            raise

        if "error" not in save_data:
            x = int(rect.width * .5)
            text.draw_text(slot_image, save_data['player_name'], (x, 0, 500, 500), font=self.font)
            text.draw_text(slot_image, save_data['time'], (x, 50, 500, 500), font=self.font)

        return slot_image
Beispiel #3
0
    def on_menu_selection(self, menuitem):
        try:
            save_data = save.load(self.selected_index + 1)

        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")

        if save_data is not None and "error" not in save_data:
            # self.save_data = save.load(self.selected_index + 1)
            # self.game.player1 = prepare.player1
            # self.game.player1.game_variables = save_data['game_variables']
            # self.game.player1.tile_pos = save_data['tile_pos']
            # self.game.player1.inventory = save_data['inventory']
            # self.game.player1.monsters = save_data['monsters']
            # self.game.player1.storage = save_data['storage']
            # self.game.player1.name = save_data['player_name']
            # tele_x = str(int(save_data['tile_pos'][0]))
            # tele_y = str(int(save_data['tile_pos'][1]))
            # location = save_data['current_map'] + ',' + tele_x + ',' + tele_y
            # action = ('teleport', location, '1', 1)

            statepoppin = self.game.current_state
            self.save_data = save.load(self.selected_index + 1)
            self.game.player1 = prepare.player1
            self.game.player1.game_variables = save_data['game_variables']
            self.game.player1.tile_pos = save_data['tile_pos']
            self.game.player1.inventory = save_data['inventory']
            self.game.player1.monsters = save_data['monsters']
            self.game.player1.storage = save_data['storage']
            self.game.player1.name = save_data['player_name']
            self.game.push_state("WorldState")
            tele_x = str(int(save_data['tile_pos'][0]))
            tele_y = str(int(save_data['tile_pos'][1]))

            Action = namedtuple("action", ["type", "parameters"])
            action = Action("teleport",
                            [save_data['current_map'], tele_x, tele_y])

            self.game.event_engine.actions['teleport']['method'](self.game,
                                                                 action)
            self.game.pop_state(statepoppin)
            self.game.replace_state("WorldState")
            self.game.event_engine.actions['teleport']['method'](self.game,
                                                                 action)
Beispiel #4
0
    def on_menu_selection(self, menuitem):
        try:
            save_data = save.load(self.selected_index + 1)

        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")

        if save_data is not None and "error" not in save_data:
            # self.save_data = save.load(self.selected_index + 1)
            # self.game.player1 = prepare.player1
            # self.game.player1.game_variables = save_data['game_variables']
            # self.game.player1.tile_pos = save_data['tile_pos']
            # self.game.player1.inventory = save_data['inventory']
            # self.game.player1.monsters = save_data['monsters']
            # self.game.player1.storage = save_data['storage']
            # self.game.player1.name = save_data['player_name']
            # tele_x = str(int(save_data['tile_pos'][0]))
            # tele_y = str(int(save_data['tile_pos'][1]))
            # location = save_data['current_map'] + ',' + tele_x + ',' + tele_y
            # action = ('teleport', location, '1', 1)

            statepoppin = self.game.current_state
            self.save_data = save.load(self.selected_index + 1)
            self.game.player1 = prepare.player1
            self.game.player1.game_variables = save_data['game_variables']
            self.game.player1.tile_pos = save_data['tile_pos']
            self.game.player1.inventory = save_data['inventory']
            self.game.player1.monsters = save_data['monsters']
            self.game.player1.storage = save_data['storage']
            self.game.player1.name = save_data['player_name']
            self.game.push_state("WorldState")
            tele_x = str(int(save_data['tile_pos'][0]))
            tele_y = str(int(save_data['tile_pos'][1]))

            Action = namedtuple("action", ["type", "parameters"])
            action = Action("teleport", [save_data['current_map'], tele_x, tele_y])

            self.game.event_engine.actions['teleport']['method'](self.game, action)
            self.game.pop_state(statepoppin)
            self.game.replace_state("WorldState")
            self.game.event_engine.actions['teleport']['method'](self.game, action)
Beispiel #5
0
    def on_menu_selection(self, menuitem):
        try:
            save_data = save.load(self.selected_index + 1)

        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")

        if save_data is not None and "error" not in save_data:
            self.save_data = save.load(self.selected_index + 1)
            self.game.player1 = prepare.player1
            self.game.player1.game_variables = save_data['game_variables']
            self.game.player1.tile_pos = save_data['tile_pos']
            self.game.player1.inventory = save_data['inventory']
            self.game.player1.monsters = save_data['monsters']
            self.game.player1.storage = save_data['storage']
            self.game.player1.name = save_data['player_name']

            old_world = self.game.get_state_name("WorldState")
            if old_world is None:
                # when game is loaded from the start menu
                self.game.pop_state()  # close this menu
                self.game.pop_state()  # close the start menu
            else:
                # when game is loaded from world menu
                self.game.pop_state(self)
                self.game.pop_state(old_world)

            self.game.push_state("WorldState")
            # self.game.current_state.change_map(save_data['current_map'])

            # teleport the player to the correct position using an event engine action
            tele_x = str(int(save_data['tile_pos'][0]))
            tele_y = str(int(save_data['tile_pos'][1]))

            self.game.event_engine.execute_action(
                'teleport', [save_data['current_map'], tele_x, tele_y])
Beispiel #6
0
    def on_menu_selection(self, menuitem):
        try:
            save_data = save.load(self.selected_index + 1)

        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")

        if save_data is not None and "error" not in save_data:
            self.save_data = save.load(self.selected_index + 1)
            self.game.player1 = prepare.player1
            self.game.player1.game_variables = save_data['game_variables']
            self.game.player1.tile_pos = save_data['tile_pos']
            self.game.player1.inventory = save_data['inventory']
            self.game.player1.monsters = save_data['monsters']
            self.game.player1.storage = save_data['storage']
            self.game.player1.name = save_data['player_name']

            old_world = self.game.get_state_name("WorldState")
            if old_world is None:
                # when game is loaded from the start menu
                self.game.pop_state()  # close this menu
                self.game.pop_state()  # close the start menu
            else:
                # when game is loaded from world menu
                self.game.pop_state(self)
                self.game.pop_state(old_world)

            self.game.push_state("WorldState")
            # self.game.current_state.change_map(save_data['current_map'])

            # teleport the player to the correct position using an event engine action
            tele_x = str(int(save_data['tile_pos'][0]))
            tele_y = str(int(save_data['tile_pos'][1]))

            self.game.event_engine.execute_action('teleport', [save_data['current_map'], tele_x, tele_y])
Beispiel #7
0
    def render_slot(self, rect, slot_num):
        slot_image = pygame.Surface(rect.size, pygame.SRCALPHA)

        thumb_image = None
        try:
            thumb_image = pygame.image.load(prepare.SAVE_PATH + str(slot_num) +
                                            ".png").convert()
            thumb_rect = thumb_image.get_rect().fit(rect)
            thumb_image = pygame.transform.smoothscale(thumb_image,
                                                       thumb_rect.size)
        except Exception as e:
            logger.error(e)

        # Try and load the save game and draw details about the save
        try:
            save_data = save.load(slot_num)
        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            save_data["player_name"] = "BROKEN SAVE!"
            logger.error("Failed loading save file.")
            if thumb_image is not None:
                pygame.draw.line(thumb_image, (255, 0, 0), [0, 0],
                                 thumb_rect.size, 3)
                pygame.draw.line(thumb_image, (255, 0, 0),
                                 [0, thumb_rect.height], [thumb_rect.width, 0],
                                 3)

        # Draw the screenshot
        if thumb_image is not None:
            slot_image.blit(thumb_image, (rect.width * .20, 0))

        # Draw the slot text
        rect = rect.move(0, rect.height // 2 - 10)
        text.draw_text(slot_image,
                       trans('slot') + " " + str(slot_num),
                       rect,
                       font=self.font)

        x = int(rect.width * .5)
        text.draw_text(slot_image,
                       save_data['player_name'], (x, 0, 500, 500),
                       font=self.font)
        if "error" not in save_data:
            text.draw_text(slot_image,
                           save_data['time'], (x, 50, 500, 500),
                           font=self.font)

        return slot_image
Beispiel #8
0
    def render_slot(self, rect, slot_num):
        slot_image = pygame.Surface(rect.size, pygame.SRCALPHA)

        # TODO: catch missing file
        thumb_image = pygame.image.load(prepare.SAVE_PATH + str(slot_num) +
                                        ".png").convert()
        thumb_rect = thumb_image.get_rect().fit(rect)
        thumb_image = pygame.transform.smoothscale(thumb_image,
                                                   thumb_rect.size)

        # Draw the screenshot
        slot_image.blit(thumb_image, (rect.width * .20, 0))

        # Draw the slot text
        rect = rect.move(0, rect.height // 2 - 10)
        text.draw_text(slot_image,
                       "Slot " + str(slot_num),
                       rect,
                       font=self.font)

        # Try and load the save game and draw details about the save
        try:
            save_data = save.load(slot_num)
        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            logger.error("Failed loading save file.")
            raise

        if "error" not in save_data:
            x = int(rect.width * .5)
            text.draw_text(slot_image,
                           save_data['player_name'], (x, 0, 500, 500),
                           font=self.font)
            text.draw_text(slot_image,
                           save_data['time'], (x, 50, 500, 500),
                           font=self.font)

        return slot_image
Beispiel #9
0
    def render_slot(self, rect, slot_num):
        slot_image = pygame.Surface(rect.size, pygame.SRCALPHA)

        thumb_image = None
        try:
            thumb_image = pygame.image.load(prepare.SAVE_PATH + str(slot_num) + ".png").convert()
            thumb_rect = thumb_image.get_rect().fit(rect)
            thumb_image = pygame.transform.smoothscale(thumb_image, thumb_rect.size)
        except Exception as e:
            logger.error(e)

        # Try and load the save game and draw details about the save
        try:
            save_data = save.load(slot_num)
        except Exception as e:
            logger.error(e)
            save_data = dict()
            save_data["error"] = "Save file corrupted"
            save_data["player_name"] = "BROKEN SAVE!"
            logger.error("Failed loading save file.")
            if thumb_image is not None:
                pygame.draw.line(thumb_image, (255,   0,   0), [0, 0], thumb_rect.size, 3)
                pygame.draw.line(thumb_image, (255,   0,   0), [0, thumb_rect.height], [thumb_rect.width, 0], 3)

        # Draw the screenshot
        if thumb_image is not None:
            slot_image.blit(thumb_image, (rect.width * .20, 0))

        # Draw the slot text
        rect = rect.move(0, rect.height // 2 - 10)
        text.draw_text(slot_image, trans('slot') + " " + str(slot_num), rect, font=self.font)

        x = int(rect.width * .5)
        text.draw_text(slot_image, save_data['player_name'], (x, 0, 500, 500), font=self.font)
        if "error" not in save_data:
            text.draw_text(slot_image, save_data['time'], (x, 50, 500, 500), font=self.font)

        return slot_image