import pygame from support import import_folder class Player(pygame.sprite.Sprite): def __init__(self, pos): super().__init__() self.import_character_assets() self.frame_index = 0 self.animation_speed = 0.15 if self.animations['idle']: self.image = self.animations['idle'][self.frame_index] else: self.image = pygame.Surface((32, 64)) self.image.fill((255, 0, 0)) print("Warning: No idle animation frames found!") self.rect = self.image.get_rect(topleft=pos) self.direction = pygame.math.Vector2(0, 0) self.speed = 8 self.gravity = 0.8 self.jump_speed = -16 def import_character_assets(self): character_path = 'W:/12/rover.paramio/Programming/Rono style platfromer/graphics/character/' self.animations = {'idle': [], 'run': [], 'jump': [], 'fall': []} for animation in self.animations.keys(): full_path = character_path + animation import os absolute_path = os.path.abspath(full_path) print(f"Looking for images in: {absolute_path}") if not os.path.exists(full_path): print(f"Folder does not exist: {full_path}") self.animations[animation] = import_folder(full_path) if not self.animations[animation]: print(f"Warning: No images found in {full_path}") def get_input(self): keys = pygame.key.get_pressed() if keys[pygame.K_RIGHT]: self.direction.x = 1 elif keys[pygame.K_LEFT]: self.direction.x = -1 else: self.direction.x = 0 if keys[pygame.K_SPACE]: self.jump() 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.rect.x += self.direction.x * self.speed