|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import os
|
|
|
from typing import Type
|
|
from typing import Type
|
|
|
|
|
|
|
|
import pygame
|
|
import pygame
|
|
@@ -94,6 +95,11 @@ class Character(pygame.sprite.Sprite):
|
|
|
|
|
|
|
|
super().__init__()
|
|
super().__init__()
|
|
|
self.load(image_filename)
|
|
self.load(image_filename)
|
|
|
|
|
+ if not animation_filenames and name:
|
|
|
|
|
+ animation_filenames = {
|
|
|
|
|
+ action: f'{name}_{action}.png'
|
|
|
|
|
+ for action in self._predefined_animations_allowed
|
|
|
|
|
+ }
|
|
|
self.set_animations(animation_filenames)
|
|
self.set_animations(animation_filenames)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
def __repr__(self):
|
|
@@ -365,6 +371,8 @@ class Character(pygame.sprite.Sprite):
|
|
|
not key or _get_keys()[utils.eval_key(key)]
|
|
not key or _get_keys()[utils.eval_key(key)]
|
|
|
):
|
|
):
|
|
|
self.is_jumping = True
|
|
self.is_jumping = True
|
|
|
|
|
+ if _('jump') in self.animation_filenames.keys():
|
|
|
|
|
+ self.load(self.animation_filenames[_('jump')])
|
|
|
|
|
|
|
|
def rotate(self, increment: int = 1):
|
|
def rotate(self, increment: int = 1):
|
|
|
"""
|
|
"""
|
|
@@ -522,12 +530,20 @@ class Character(pygame.sprite.Sprite):
|
|
|
if not isinstance(animations, dict):
|
|
if not isinstance(animations, dict):
|
|
|
raise TypeError(_('The animations must be a dict.'))
|
|
raise TypeError(_('The animations must be a dict.'))
|
|
|
|
|
|
|
|
- self.animation_filenames = dict(
|
|
|
|
|
|
|
+ filtered_allowed_animations = dict(
|
|
|
filter(
|
|
filter(
|
|
|
lambda pair: pair[0] in self._predefined_animations_allowed,
|
|
lambda pair: pair[0] in self._predefined_animations_allowed,
|
|
|
animations.items(),
|
|
animations.items(),
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
|
|
+ self.animation_filenames = dict(
|
|
|
|
|
+ filter(
|
|
|
|
|
+ lambda pair: os.path.isfile(
|
|
|
|
|
+ os.path.join(settings.CHARACTERS_DIR, pair[1])
|
|
|
|
|
+ ),
|
|
|
|
|
+ filtered_allowed_animations.items(),
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
def set_chronometer(self, time: int):
|
|
def set_chronometer(self, time: int):
|
|
|
"""
|
|
"""
|
|
@@ -829,6 +845,7 @@ class Character(pygame.sprite.Sprite):
|
|
|
else:
|
|
else:
|
|
|
self._jump_counter = settings.DEFAULT_JUMP_FORCE
|
|
self._jump_counter = settings.DEFAULT_JUMP_FORCE
|
|
|
self.is_jumping = False
|
|
self.is_jumping = False
|
|
|
|
|
+ self.load(self.image_filename)
|
|
|
|
|
|
|
|
def _update_rect_position(
|
|
def _update_rect_position(
|
|
|
self,
|
|
self,
|