|
@@ -34,6 +34,7 @@ class Character(pygame.sprite.Sprite):
|
|
|
_('down'),
|
|
_('down'),
|
|
|
_('forward'),
|
|
_('forward'),
|
|
|
_('jump'),
|
|
_('jump'),
|
|
|
|
|
+ _('stop'),
|
|
|
_('up'),
|
|
_('up'),
|
|
|
]
|
|
]
|
|
|
|
|
|
|
@@ -100,6 +101,7 @@ class Character(pygame.sprite.Sprite):
|
|
|
action: f'{name}_{action}.png'
|
|
action: f'{name}_{action}.png'
|
|
|
for action in self._predefined_animations_allowed
|
|
for action in self._predefined_animations_allowed
|
|
|
}
|
|
}
|
|
|
|
|
+ animation_filenames.update({_('stop'): f'{name}.png'})
|
|
|
self.set_animations(animation_filenames)
|
|
self.set_animations(animation_filenames)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
def __repr__(self):
|
|
@@ -372,7 +374,9 @@ class Character(pygame.sprite.Sprite):
|
|
|
):
|
|
):
|
|
|
self.is_jumping = True
|
|
self.is_jumping = True
|
|
|
if _('jump') in self.animation_filenames.keys():
|
|
if _('jump') in self.animation_filenames.keys():
|
|
|
- self.load(self.animation_filenames[_('jump')])
|
|
|
|
|
|
|
+ self.load(
|
|
|
|
|
+ self.animation_filenames[_('jump')], preserve_size=True
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
def rotate(self, increment: int = 1):
|
|
def rotate(self, increment: int = 1):
|
|
|
"""
|
|
"""
|
|
@@ -800,7 +804,7 @@ class Character(pygame.sprite.Sprite):
|
|
|
return self.STATIC_COLLISION
|
|
return self.STATIC_COLLISION
|
|
|
return ''
|
|
return ''
|
|
|
|
|
|
|
|
- def load(self, filename: str):
|
|
|
|
|
|
|
+ def load(self, filename: str, preserve_size: bool = False):
|
|
|
"""
|
|
"""
|
|
|
>>> protagonist = Character('protagonist.png')
|
|
>>> protagonist = Character('protagonist.png')
|
|
|
>>> protagonist.load('secondary.png')
|
|
>>> protagonist.load('secondary.png')
|
|
@@ -808,12 +812,15 @@ class Character(pygame.sprite.Sprite):
|
|
|
self._original_image, self._original_rect = utils._load_image(
|
|
self._original_image, self._original_rect = utils._load_image(
|
|
|
settings.CHARACTERS_DIR, filename
|
|
settings.CHARACTERS_DIR, filename
|
|
|
)
|
|
)
|
|
|
-
|
|
|
|
|
|
|
+ if preserve_size:
|
|
|
|
|
+ height = self.height
|
|
|
self.image = self._original_image
|
|
self.image = self._original_image
|
|
|
self._original_rect = self._original_image.get_rect()
|
|
self._original_rect = self._original_image.get_rect()
|
|
|
self.rect = self.image.get_rect()
|
|
self.rect = self.image.get_rect()
|
|
|
self.scale_factor = 1
|
|
self.scale_factor = 1
|
|
|
self.image_filename = filename
|
|
self.image_filename = filename
|
|
|
|
|
+ if preserve_size:
|
|
|
|
|
+ self.set_height(height)
|
|
|
|
|
|
|
|
def copy(self):
|
|
def copy(self):
|
|
|
"""
|
|
"""
|
|
@@ -845,7 +852,9 @@ 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)
|
|
|
|
|
|
|
+ self.load(
|
|
|
|
|
+ self.animation_filenames[_('stop')], preserve_size=True
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
def _update_rect_position(
|
|
def _update_rect_position(
|
|
|
self,
|
|
self,
|