def __init__(self, surface, img, offset, y_range, speed=10): self.surface = surface self.img = img self.offset = offset self.y_range = y_range self.speed = speed self.start_x_pos = Surface.get_width(self.surface) + self.offset self.y_pos = randint( Surface.get_height(self.surface) / 2 - self.y_range, Surface.get_height(self.surface) / 2 + self.y_range) self.img_bounds = list(Surface.get_bounding_rect(self.img)) self.img_width = self.img_bounds[2] self.img_height = self.img_bounds[3]
def __init__(self, surface, img_path): self.surface = surface self.x_pos = Surface.get_width(self.surface) / 2 self.y_pos = 0 self.img = image.load(img_path) self.hold_y_pos = False self.spawn_in = True self.player_rect = [self.x_pos, self.y_pos, 10, 10] # x_pos, y_pos, rect_width, rect_height self.img_bounds = list(Surface.get_bounding_rect(self.img)) self.img_width = self.img_bounds[2] self.img_height = self.img_bounds[3] self.jumps_remaining = 2 self.jumping = False self.hp = 100
def crop_whitespace(surf: pygame.Surface): rect = surf.get_bounding_rect() new_surf = pygame.Surface(rect.size, pygame.SRCALPHA) new_surf.blit(surf, (0, 0), rect) return new_surf, surf.get_rect()