Beispiel #1
0
    def _load_tiles(self):
        """
        Load basic tile textures.
        """
        hex_rad = self._master.hex_rad

        tile_text = \
            pygame.image.load(self._ui_dir+"tile.png").convert_alpha()

        target_size = hex_math.hex_rectangle_size(hex_rad)
        target_size = (target_size[0]-self._master.tile_pad, 
                       target_size[1]-self._master.tile_pad)

        scaled_tile = \
            pygame.transform.smoothscale(tile_text, target_size)

        alpha = pygame.surfarray.pixels_alpha(scaled_tile)
        alpha[(alpha > 0).nonzero()] = 128
        self._tile_text = {}
        self._tile_text["BASE"] = scaled_tile
        
        self._overlay_text = {}
        for color_name in colors.colors.keys():
            overlay = self._tile_text["BASE"].copy()
            values = pygame.surfarray.pixels3d(overlay)        
            values[:,:,0] = colors.colors[color_name][0]
            values[:,:,1] = colors.colors[color_name][1]
            values[:,:,2] = colors.colors[color_name][2]
            self._overlay_text[color_name] = overlay
Beispiel #2
0
    def _make_blank_board(self):
        """
        Make a blank, transparent surface of size matched to the
        board. This will serve as a base for rendering the board
        contents.
        """
        board = self._master.game.board
        hex_rad = self._master.hex_rad
        hex_rect = hex_math.hex_rectangle_size(hex_rad)

        min_world = (0,0)
        max_world = (0,0)
        
        for h in board.border:
            coords = hex_math.hex_to_world(h, hex_rad)            
            if (coords[0]-hex_rect[0]*0.5) < min_world[0]:
                min_world = (coords[0]-hex_rect[0]*0.5, min_world[1])
            if (coords[1]-hex_rect[1]*0.5) < min_world[1]:
                min_world = (min_world[0], coords[1]-hex_rect[1]*0.5)
            if (coords[0]+hex_rect[0]*0.5) > max_world[0]:
                max_world = (coords[0]+hex_rect[0]*0.5, max_world[1])
            if (coords[1]+hex_rect[1]*0.5) > max_world[1]:
                max_world = (max_world[0],coords[1]+hex_rect[1]*0.5)

        self._board_size = ((int) (max_world[0]-min_world[0]),
                            (int) (max_world[1]-min_world[1]))
        self._board_origin = (int(self._board_size[0]*0.5),
                              int(self._board_size[1]*0.5))

        self._blank_board_contents = \
            pygame.Surface((self._board_size[0], self._board_size[1]) \
                               ).convert_alpha()
        alpha = pygame.surfarray.pixels_alpha(self._blank_board_contents)
        alpha[(alpha > 0).nonzero()] = 0
Beispiel #3
0
 def _load_ship_texture(self, ship, preserve_aspect=True):
     """
     Load the board textures.
     """
     texture = \
         pygame.image.load(self._ship_dir+ \
                               ship.imname).convert_alpha()
     hex_rect = hex_math.hex_rectangle_size(self._master.hex_rad)
     if preserve_aspect:
         width = texture.get_width()
         height = texture.get_height()
         fac_width = (1.0*width) / (1.0*hex_rect[0])
         fac_height = (1.0*height) / (1.0*hex_rect[1])
         if fac_width <= fac_height:
             target_size = ((1.0*width)/(1.0*fac_height),
                             (1.0*height)/(1.0*fac_height))
         else:
             target_size = ((1.0*width)/(1.0*fac_width),
                             (1.0*height)/(1.0*fac_width))
     else:
         target_size = (self._master.screen_size[0],
                         self._master.screen_size[1])
     scaled_texture = \
         pygame.transform.smoothscale(texture, target_size)
     ship.texture = scaled_texture