|
|
@@ -24,10 +24,11 @@ class Character(pygame.sprite.Sprite):
|
|
|
A videogame character with a bunch of actions.
|
|
|
"""
|
|
|
|
|
|
- TOP = _('top')
|
|
|
- BOTTOM = _('bottom')
|
|
|
- LEFT = _('left')
|
|
|
- RIGHT = _('right')
|
|
|
+ TOP_COLLISION = _('top')
|
|
|
+ BOTTOM_COLLISION = _('bottom')
|
|
|
+ LEFT_COLLISION = _('left')
|
|
|
+ RIGHT_COLLISION = _('right')
|
|
|
+ STATIC_COLLISION = _('static')
|
|
|
|
|
|
_predefined_key_actions_allowed = [
|
|
|
_('backward'),
|
|
|
@@ -535,7 +536,7 @@ class Character(pygame.sprite.Sprite):
|
|
|
self,
|
|
|
other_characters: Type['Character'] | Type['jogai.group.Group'] | list,
|
|
|
key: str = '',
|
|
|
- ) -> bool:
|
|
|
+ ) -> str:
|
|
|
"""
|
|
|
Detect if one character is touching another(s).
|
|
|
|
|
|
@@ -549,7 +550,7 @@ class Character(pygame.sprite.Sprite):
|
|
|
>>> protagonist = Character('protagonist.png')
|
|
|
>>> secondary = Character('secondary.png')
|
|
|
>>> protagonist.touch(secondary)
|
|
|
- True
|
|
|
+ 'static'
|
|
|
"""
|
|
|
|
|
|
if isinstance(other_characters, Character):
|
|
|
@@ -577,14 +578,16 @@ class Character(pygame.sprite.Sprite):
|
|
|
for other_character in other_characters:
|
|
|
if not key or _get_keys()[utils.eval_key(key)]:
|
|
|
if self.rect.colliderect(other_character.rect):
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
- def collide(
|
|
|
- self,
|
|
|
- other_characters: Type['Character'] | Type['jogai.group.Group'] | list,
|
|
|
- ):
|
|
|
- ...
|
|
|
+ if self.velocity.y > 0:
|
|
|
+ return self.TOP_COLLISION
|
|
|
+ elif self.velocity.y < 0:
|
|
|
+ return self.BOTTOM_COLLISION
|
|
|
+ if self.velocity.x > 0:
|
|
|
+ return self.LEFT_COLLISION
|
|
|
+ elif self.velocity.x < 0:
|
|
|
+ return self.RIGHT_COLLISION
|
|
|
+ return self.STATIC_COLLISION
|
|
|
+ return ''
|
|
|
|
|
|
def load(self, filename: str):
|
|
|
"""
|