Ejemplo n.º 1
0
 def get_destination(self, start, direction,
                     distance) -> board_position.BoardPosition:
     exact_position_x = start.x + math.sin(
         math.radians(direction)) * distance
     exact_position_y = start.y - math.cos(
         math.radians(direction)) * distance
     return board_position.BoardPosition(exact_position_x, exact_position_y)
Ejemplo n.º 2
0
 def get_destination_rect(self, distance: int) -> board_rect.BoardRect:
     destination_rect = self.get_destination(self.token.position,
                                             self.token.direction, distance)
     destination_rect = board_position.BoardPosition(
         destination_rect[0], destination_rect[1])
     rect = destination_rect.to_rect(self.token.rect)
     rect.center = self.token.position
     return rect
Ejemplo n.º 3
0
 def position(self, value: Union[board_position.BoardPosition, tuple]):
     self.last_position = self.position
     self.last_direction = self.direction
     if type(value) == tuple:
         value = board_position.BoardPosition(value[0], value[1])
     self._position = value
     if self.last_position != self.position:
         self.dirty = 1
         if self.board:
             self.board.window.send_event_to_containers("token_moved", self)
Ejemplo n.º 4
0
 def get_line_to(self, start, target):
     sampling_rate = int(
         math.sqrt((target[0] - start[0])**2 + target[1] - start[1]**2))
     x_spacing = (target[0] - start[0]) / (sampling_rate + 1)
     y_spacing = (target[1] - start[1]) / (sampling_rate + 1)
     return [
         board_position.BoardPosition(start[0] + i * x_spacing,
                                      start[1] + i * y_spacing)
         for i in range(1, sampling_rate + 1)
     ]
Ejemplo n.º 5
0
 def _get_position_from_parameter(self, parameter):
     if type(parameter) == tuple:
         pos = board_position.BoardPosition(parameter[0], parameter[1])
     elif type(parameter) == board_position.BoardPosition:
         pos = parameter
     elif type(parameter) == board_rect.BoardRect:
         pos = board_position.BoardPosition.from_rect(parameter)
     else:
         raise TypeError("Parameter must be tuple, BoardPosition or Rect")
     return parameter
    def get_event(self, event, data):
        super().get_event(event, data)
        if self.selected_token_type:
            if "mouse_left" in event:
                if self.board.is_in_container(data[0], data[1]):
                    keys = self.board.window.get_keys()
                    if "L_SHIFT" in keys:
                        for i in range(self.board.rows):
                            for j in range(self.board.columns):
                                self.selected_token_type((j, i))
                    else:
                        try:
                            import miniworldmaker.board_positions.board_position as bp
                            self.selected_token_type(
                                position=bp.BoardPosition.from_pixel(data))
                        except TypeError:
                            print(
                                "Can't create tokens with more than one parameter position yet"
                            )

            elif "wheel_up" in event or "wheel_down" in event:
                if self.board.is_in_container(data[0], data[1]):
                    token = self.board.get_token_in_area(data)
                    for cls in token.__class__.__mro__:
                        if cls.__name__ == "Actor":
                            if event == "wheel_up":
                                token.turn_left(5)
                            elif event == "wheel_down":
                                token.turn_right(5)
            elif "mouse_motion" in event:
                if pygame.mouse.get_pressed()[0] == 1:
                    if self.board.is_in_container(data[0], data[1]):
                        rect = board_position.BoardPosition(data[0],
                                                            data[1]).to_rect()
                        token = self.board.get_tokens_at_rect(rect,
                                                              singleitem=True)
                        if token.__class__ != self.selected_token_type:
                            import miniworldmaker.board_positions.board_position as bp
                            token = self.selected_token_type(
                                position=bp.BoardPosition.from_pixel(data))
        if "mouse_right" in event:
            if self.board.is_in_container(data[0], data[1]):
                keys = self.board.window.get_keys()
                if "L_SHIFT" in keys:
                    tokens = self.board.get_tokens_by_pixel(data)
                    while tokens:
                        token = tokens.pop()
                        token.remove()
                else:
                    tokens = self.board.get_tokens_by_pixel(data)
                    if tokens:
                        tokens[0].turn_left(5)
Ejemplo n.º 7
0
    def color_at(self, position: board_position.BoardPosition) -> tuple:
        """
        Returns the color at a specific position

        Args:
            position: The position to search for

        Returns: The color

        """
        if type(position) == tuple:
            position = board_position.BoardPosition(position[0], position[1])
        if position.is_on_board():
            return self._image.get_at(position.to_pixel())
Ejemplo n.º 8
0
    def is_position_on_board(self, position: board_position.BoardPosition) -> bool:
        """Tests if area or position is on board

        Args:
            position: A rectangle or a position

        Returns:
            true, if area is in grid

        """
        if type(position) == tuple:
            position = board_position.BoardPosition(position[0], position[1])
        if type(position) == board_position.BoardPosition:
            position = position.to_rect()

        top_left_x, top_left_y, right, top = position.topleft[0], \
                                             position.topleft[1], \
                                             position.right, \
                                             position.top
        if top_left_x < 0 or top_left_y < 0 or position.right >= self.width or position.bottom >= self.height:
            return False
        else:
            return True
Ejemplo n.º 9
0
 def get_colors_at_position(self, position: Union[tuple, board_position.BoardPosition]):
     if type(position) == tuple:
         position = board_position.BoardPosition(position[0], position[1])
     return position.color()
Ejemplo n.º 10
0
 def center(self) -> board_position.BoardPosition:
     return board_position.BoardPosition(self.center_x, self.center_y)
Ejemplo n.º 11
0
 def topleft(self) -> board_position.BoardPosition:
     return board_position.BoardPosition(self.rect.topleft[0],
                                         self.rect.topleft[1])
Ejemplo n.º 12
0
 def get_destination(self, start, direction, distance) -> board_position.BoardPosition:
     x = start[0] + round(math.sin(math.radians(direction)) * distance)
     y = start[1] - round(math.cos(math.radians(direction)) * distance)
     return board_position.BoardPosition(x, y)
Ejemplo n.º 13
0
 def is_on_board(self):
     topleft_on_board = board_position.BoardPosition(
         self.left, self.top).is_on_board()
     bottom_right_on_board = board_position.BoardPosition(
         self.right, self.bottom).is_on_board()
     return topleft_on_board or bottom_right_on_board