import pygame from support import import_folder class Player(pygame.sprite.Sprite): def __init__(self, pos,surface,jump_particles): super().__init__() self.import_char_assets() self.frame_index = 0 self.animation_speed = 0.15 self.image = self.animations['idle'][self.frame_index] self.rect = self.image.get_rect(topleft = pos) self.import_dust_run() self.dust_frame_index = 0 self.dust_anim_speed = 0.15 self.display_surface = surface self.create_jump_particles = jump_particles self.direction = pygame.math.Vector2(0,0) self.speed = 8 self.gravity = 0.981 self.jump_speed = -18 self.status = 'idle' self.facing_right = True self.on_ground = False self.on_ceiling = False self.on_right = False self.on_left = False def import_char_assets(self): # Adjust the path to match your new folder structure character_path = 'graphics.C/character/' self.animations = {'idle': [], 'run': [], 'jump': [], 'fall': []} for animation in self.animations.keys(): full_path = character_path + animation print(f"Loading animation from: {full_path}") # Debug print self.animations[animation] = import_folder(full_path) def import_dust_run(self): self.dust_run = import_folder('graphics.C/character/dust_particles/run') def run_dust_animation(self): if self.status == 'run' and self.on_ground: self.dust_frame_index += self.dust_anim_speed if self.dust_frame_index >= len(self.dust_run): self.dust_frame_index = 0 dust_particle = self.dust_run[int(self.dust_frame_index)] if self.facing_right: pos = self.rect.bottomleft - pygame.math.Vector2(6,10) self.display_surface.blit(dust_particle, pos) else: pos = self.rect.bottomright - pygame.math.Vector2(6,10) flip_dust = pygame.transform.flip(dust_particle, True, False) self.display_surface.blit(flip_dust, pos) def animate(self): animation = self.animations[self.status] self.frame_index += self.animation_speed if self.frame_index >= len(animation): self.frame_index = 0 image = animation[int(self.frame_index)] if self.facing_right: self.image = image else: flip = pygame.transform.flip(image, True, False) self.image = flip if self.on_ground and self.on_right: self.rect = self.image.get_rect(bottomright = self.rect.bottomright) elif self.on_ground and self.on_left: self.rect = self.image.get_rect(bottomleft = self.rect.bottomleft) elif self.on_ground: self.rect = self.image.get_rect(midbottom = self.rect.midbottom) elif self.on_ceiling and self.on_right: self.rect = self.image.get_rect(topright = self.rect.topright) elif self.on_ceiling and self.on_left: self.rect = self.image.get_rect(topleft = self.rect.topleft) elif self.on_ceiling: self.rect = self.image.get_rect(midtop = self.rect.midtop) def get_input(self): keys = pygame.key.get_pressed() if keys[pygame.K_RIGHT] or keys[pygame.K_d]: self.direction.x = 1 self.facing_right = True elif keys[pygame.K_LEFT] or keys[pygame.K_a]: self.direction.x = -1 self.facing_right = False else: self.direction.x = 0 if keys[pygame.K_SPACE] and self.on_ground: self.jump() self.create_jump_particles(self.rect.midbottom) def get_status(self): if self.direction.y < 0: self.status = 'jump' elif self.direction.y > 1: self.status = "fall" else: if self.direction.x != 0: self.status = "run" else: self.status = "idle" def apply_gravity(self): self.direction.y += self.gravity self.rect.y += self.direction.y def jump(self): self.direction.y = self.jump_speed def update(self): self.get_input() self.animate() self.get_status() self.run_dust_animation()