Example #1
0
    def blit_rotate(surf: pygame.SurfaceType, image: pygame.SurfaceType, pos: Vector, angle: float,
                    origin_pos: Vector = None, show_rect: bool = False) -> None:
        """Many thanks to https://stackoverflow.com/a/54714144."""
        # calculate the axis aligned bounding box of the rotated image
        w, h = image.get_size()
        box = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]]
        box_rotate = [p.rotate(angle) for p in box]
        min_box = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1])
        max_box = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1])

        # calculate the translation of the pivot
        if origin_pos is None:
            origin_pos = w / 2, h / 2
        pivot = pygame.math.Vector2(origin_pos[0], -origin_pos[1])
        pivot_rotate = pivot.rotate(angle)
        pivot_move = pivot_rotate - pivot

        # calculate the upper left origin of the rotated image
        origin = (pos[0] - origin_pos[0] + min_box[0] - pivot_move[0],
                  pos[1] - origin_pos[1] - max_box[1] + pivot_move[1])
        # get a rotated image
        rotated_image = pygame.transform.rotate(image, angle)
        # rotate and blit the image
        surf.blit(rotated_image, origin)
        # draw rectangle around the image
        if show_rect:
            pygame.draw.rect(surf, (255, 0, 0), (*origin, *rotated_image.get_size()), 2)
Example #2
0
 def draw(self, screen: pygame.SurfaceType, name: bool = False):
     screen.blit(self._ball, self.rect)
     if name:
         text = self.font.render(self.name, True, (0, 0, 0))
         text_rect = self.rect
         text_rect.topleft = self.rect.center
         screen.blit(text, self.rect)
Example #3
0
 def render(self, window_surface: pygame.SurfaceType):
     text_height_offset = 0
     for index, ui_text in enumerate(self.init_text_ui()):
         text_height = ui_text.get_height()
         window_surface.blit(ui_text,
                             (self.x_pos, self.y_pos + text_height_offset +
                              (self.line_spacing if index == 0 else 0)))
         text_height_offset += text_height
 def render(self, window_surface: pygame.SurfaceType):
     if self.is_obstacle():
         self.block.fill(OBSTACLE_COLOR)
     elif self.marked:
         self.block.fill(MARKER_COLOR)
     elif self.is_path:
         self.block.fill(PATH_COLOR)
     elif self.get_visited():
         self.block.fill(VISITED_COLOR)
     else:
         if self.get_distance() == sys.maxsize:
             self.block.fill(UNVISITED_COLOR)
         else:
             self.block.fill(SEARCHED_COLOR)
     if self.debug_mode:
         if self.get_distance() != sys.maxsize:
             if type(self.debug_text) is list:
                 render_multiline_text(self.block, self.debug_text, 8, (0, 0, 0))
             if type(self.debug_text) == str:
                 render_inline_text(self.block, self.debug_text, 8, (0, 0, 0))
     window_surface.blit(self.border, self.border_rect)
     window_surface.blit(self.block, self.block_rect)
Example #5
0
    def draw(self, surface: pygame.SurfaceType):
        surface.fill(BACKGROUND_COLOR)
        image = self.scaled_image.copy()

        for plant in self.environment.plants:
            radius = self.scale // 2 - 1
            params = (image, *(plant.position * self.scale + radius), radius, plant.get_color())
            gfxdraw.aacircle(*params)
            gfxdraw.filled_circle(*params)

        for corpse in self.environment.corpses:
            radius = self.scale // 2 - 1
            params = (image, *(corpse.position * self.scale + radius), radius, corpse.get_color())
            gfxdraw.aacircle(*params)
            gfxdraw.filled_circle(*params)

        for creature in self.environment.creatures:
            radius = int(self.scale / 2 * creature.get_size())
            radius = radius if creature.get_size() < 1 else radius - 1
            params = (image, *(creature.position * self.scale + radius), radius, creature.get_color())
            gfxdraw.aacircle(*params)
            gfxdraw.filled_circle(*params)

        surface.blit(image, -np.array(self.rect.center) + self.position)
Example #6
0
    def draw(self, screen: pygame.SurfaceType):
        p = self.pos_platform
        x, y = self.pos

        screen.blit(self.imgs[self.level][0], (x,  y + p))
        screen.blit(self.imgs[self.level][1], self.pos)
        screen.blit(self.imgs[self.level][2],
                    (x, y + p + self.imgs[self.level][0].get_height() - 3))

        for stone in self.stones:
            stone.draw(screen)
Example #7
0
    def draw(self, surface: pygame.SurfaceType):
        surface.blit(self.surface, self.position)

        # only draw if there is something to draw
        if self.text.text:
            self.text.draw(surface)
Example #8
0
 def draw(self, surface: pygame.SurfaceType):
     """
     Doesnt draw text to decrease time spent on drawing
     """
     surface.blit(self.surface, self.position)
Example #9
0
    def draw(self, surface: pygame.SurfaceType):
        s = pygame.Surface(self.size, pygame.SRCALPHA)
        s.fill(self.color)

        surface.blit(s, self.position)
        self.text.draw(surface)
Example #10
0
 def draw(self, screen: pygame.SurfaceType):
     if self.good:
         screen.blit(self.img, self.pos)
Example #11
0
 def draw(self, screen: pygame.SurfaceType):
     # pygame.draw.rect(screen, (255, 0, 0), self.rect)
     screen.blit(self.img, self.pos)
     for button in self.buttons:
         button.draw(screen)