Exemplo n.º 1
0
    def zoom_factor(self, factor):
        """
        Set the zoom factor. A higher zoom factor results in bigger tile sizes in the viewport.
        :param factor: Float zoom factor
        :return: None
        """
        self._zoom_factor = max(min(INTERFACE.MAX_ZOOM_FACTOR, factor),
                                INTERFACE.MIN_ZOOM_FACTOR)

        # Calculate new tile size
        default_tile_size = 50
        self.tile_size = int(default_tile_size * self.zoom_factor)

        # Initialize render font, a size of roughly 1,5 times the tileSize gives good results
        self._viewPortFont = GuiUtilities.viewport_font(self.tile_size)

        # Determine max coordinates for view port location
        total_width = self.player.level.map.width * self.tile_size
        total_height = self.player.level.map.height * self.tile_size
        self._renderViewPortMaxX = total_width - self.surface_viewport.get_width(
        )
        self._renderViewPortMaxY = total_height - self.surface_viewport.get_height(
        )
        if self._renderViewPortMaxX < 0:
            self._renderViewPortMaxX = 0
        if self._renderViewPortMaxY < 0:
            self._renderViewPortMaxY = 0

        # Prepare fog of war tile (used as overlay later)
        self.fogOfWarTileSurface = pygame.Surface(
            (self.tile_size, self.tile_size), pygame.SRCALPHA)
        self.fogOfWarTileSurface.fill((0, 0, 0, 140))

        # Re-initialize sprites
        initialize_sprites(self.tile_size)
Exemplo n.º 2
0
    def render_init(self):
        """
        Initializes rendering parameters
        Prepares and scales tileset.
        This function should be called on window resizing, loading a new level and changing zoom levels.
        """
        if self.game_server is None:
            return
        # Initialize maximum tile size for current viewport
        vp_width = self.surface_viewport.get_size()[0]
        vp_height = self.surface_viewport.get_size()[1]
        max_tile_width = int(vp_width // self.render_level.map["width"])
        max_tile_height = int(vp_height // self.render_level.map["height"])
        if max_tile_width < max_tile_height:
            max_tile_size = max_tile_width
        else:
            max_tile_size = max_tile_height
        # Take into account the zoom factor
        self._tileSize = int(max_tile_size * self.zoom_factor)

        # Initialize render font, a size of roughly 1,5 times the tileSize gives good results
        self._viewPortFont = GuiUtilities.viewport_font(self.tile_size)

        # Determine max coords for view port location
        total_width = self.render_level.map["width"] * self.tile_size
        total_height = self.render_level.map["height"] * self.tile_size
        self._renderViewPortMaxX = total_width - self._render_viewport_w
        self._renderViewPortMaxY = total_height - self._render_viewport_h
        if self._renderViewPortMaxX < 0:
            self._renderViewPortMaxX = 0
        if self._renderViewPortMaxY < 0:
            self._renderViewPortMaxY = 0

        # Prepare fog of war tile (used as overlay later)
        self.fogOfWarTileSurface = pygame.Surface((self.tile_size, self.tile_size), pygame.SRCALPHA)
        self.fogOfWarTileSurface.fill((0, 0, 0, 140))

        # Re-initialize sprites
        initialize_sprites(self.tile_size)