def draw_health_bar(self, screen, target_rect): if self.health != self.max_health: health_rect = Rect(0, 0, 25, 7) health_rect.bottom = target_rect.top - 2 health_rect.centerx = target_rect.centerx pygame.draw.rect(screen, Color('gray'), health_rect) health_rect.width *= self.health / self.max_health pygame.draw.rect(screen, Color('red'), health_rect)
def adjust_rect(rect: Rect, x: int, y: int, align: str = "center", vertical_align: str = "middle") -> Rect: if align == "left": rect.left = x elif align == "right": rect.right = x else: rect.centerx = x if vertical_align == "top": rect.top = y elif vertical_align == "bottom": rect.bottom = y else: rect.centery = y return rect