コード例 #1
0
ファイル: board_renderer.py プロジェクト: akleroy/blueshift
    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
コード例 #2
0
ファイル: board_renderer.py プロジェクト: akleroy/blueshift
    def _render_ships(self):
        pan = self._master.pan_manager.pan
        pan = (-1*(pan[0]), -1*(pan[1]))

        hex_rad = self._master.hex_rad
        origin = self._board_origin

        tile_width = self._overlay_text["LIGHT_GRAY"].get_width()
        tile_height = self._overlay_text["LIGHT_GRAY"].get_height()
        world = hex_math.hex_to_world(self._master.game.active_ship.hex_pos(), 
                                      hex_rad)
        x = round(world[0] - tile_width/2.0 + origin[0]) + pan[0]
        y = round(world[1] - tile_height/2.0 + origin[1]) + pan[1]
        self._master.screen.blit( \
            self._overlay_text["PALE_GREEN"], (x,y))

        for ship in self._master.game.ships:
            if ship.texture == None:
                self._load_ship_texture(ship)
            texture = ship.texture.copy()        
            angle = ship.angle_degrees()
            texture = pygame.transform.rotate(texture, angle)
            world = ship.world_pos()
            height = texture.get_height()
            width = texture.get_width()
            x = round(world[0] - width/2.0 + origin[0]) + pan[0]
            y = round(world[1] - height/2.0 + origin[1]) + pan[1]
            self._master.screen.blit(texture, (x,y))
コード例 #3
0
ファイル: ship_animation.py プロジェクト: akleroy/blueshift
    def __init__(self,
                 ship=None,
                 start_pos=None,
                 stop_pos=None,
                 csys_pos="HEX",
                 start_ang=None,
                 stop_ang=None,
                 csys_ang="DEG",
                 frac_rate=1./10.
                 ):
        """
        """
        self._ship = ship
        self._game = self._ship._game

        if csys_pos == "HEX":
            hex_rad = self._game.hex_rad
            self._start_pos = hex_math.hex_to_world(start_pos, hex_rad)
            self._stop_pos = hex_math.hex_to_world(stop_pos, hex_rad)
        else:
            self._start_pos = start_pos
            self._stop_pos = stop_pos

        if csys_ang == "HEX":
            self._start_ang = -1.0*Hex_Direction(start_ang).degrees()
            self._stop_ang = -1.0*Hex_Direction(stop_ang).degrees()
        else:
            self._start_ang = start_ang
            self._stop_ang = stop_ang
        if abs(self._stop_ang - self._start_ang) > 180.0:
            start = self._start_ang 
            stop = self._stop_ang
            if abs(start+360. - stop) <= 180.0:
                self._start_ang += 360
            elif abs(start-360. - stop) <= 180.0:
                self._start_ang -= 360

        self._frac_rate = frac_rate
        self._progress = 0.0
        self._done = False
コード例 #4
0
ファイル: board_renderer.py プロジェクト: akleroy/blueshift
    def _render_board_tiles(self):
        hex_rad = self._master.hex_rad
        board = self._master.game.board
        origin = self._board_origin

        tile_width = self._overlay_text["LIGHT_GRAY"].get_width()
        tile_height = self._overlay_text["LIGHT_GRAY"].get_height()
        
        active = self._master.game.active_ship.hex_pos()

        for h in board.hexes:
            world = hex_math.hex_to_world(h, hex_rad)
            x = round(world[0] - tile_width/2.0 + origin[0])
            y = round(world[1] - tile_height/2.0 + origin[1])
            self._blank_board_contents.blit( \
                self._overlay_text["LIGHT_GRAY"], (x,y))

        for h in board.border:
            world = hex_math.hex_to_world(h, hex_rad)
            x = round(world[0] - tile_width/2.0 + origin[0])
            y = round(world[1] - tile_height/2.0 + origin[1])
            self._blank_board_contents.blit( \
                self._overlay_text["INDIAN_RED"], (x,y))
コード例 #5
0
ファイル: pan_manager.py プロジェクト: akleroy/blueshift
 def center_on_target(self, 
                      coords, 
                      csys="HEX",
                      tick=1./50.):
     if csys == "HEX":
         coords = hex_math.hex_to_world(coords, self._master.hex_rad)
     origin = self._master.board_renderer.board_world_origin
     self._start_pan = self._pan
     self._stop_pan = ((coords[0] + origin[0] - \
                                 self._master.screen_size[0]/2.0),
                       (coords[1] + origin[1] - \
                            self._master.screen_size[1]/2.0))
     self._progress = 0.0
     self._autopan = True
     self._step = tick
コード例 #6
0
ファイル: ship.py プロジェクト: akleroy/blueshift
 def world_pos(self):
     if self._animations != []:
         active_anim = self._animations[0]
         return active_anim.world_pos()
     return hex_math.hex_to_world((self._pos.x, self._pos.y), \
                                      self._game.hex_rad)