Explorar el Código

bug fixed in _update_rect_positon()

Zero! Studio hace 1 año
padre
commit
550813db9e
Se han modificado 6 ficheros con 22 adiciones y 14 borrados
  1. 2 2
      data/02.yaml
  2. BIN
      images/characters/protagonist_jump.png
  3. 18 1
      jogai/character.py
  4. 1 1
      jogai/scene.py
  5. 0 9
      jogai/videogame.py
  6. 1 1
      scripts/basics.py

+ 2 - 2
data/02.yaml

@@ -3,13 +3,13 @@ gravity: 5
 scene: test_large.png
 characters:
   protagonist:
-    gravitative: True
+    gravitative: False
     chronometer: 30
     score: 10
     lives: 5
     speed: 20
     width: 50
-    position: [465, 300]
+    position: [2065, 300]
     keys:
       forward: RIGHT
       backward: LEFT

BIN
images/characters/protagonist_jump.png


+ 18 - 1
jogai/character.py

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

+ 1 - 1
jogai/scene.py

@@ -111,7 +111,7 @@ class Scene:
         elif (
             settings.WINDOW_WIDTH // 2
             < x
-            < self.rect.width - settings.WINDOW_WIDTH
+            < self.rect.width - settings.WINDOW_WIDTH // 2
         ):
             self.rect.x = -x + settings.WINDOW_WIDTH // 2
         else:

+ 0 - 9
jogai/videogame.py

@@ -27,15 +27,6 @@ _predefined_attributes_allowed = [
 # ------------------ #
 
 
-def _check_for_character_animation_files(path: str, filenames: dict):
-    return dict(
-        filter(
-            lambda filename: os.path.isfile(os.path.join(path, filename[1])),
-            filenames,
-        )
-    )
-
-
 def _load_scene(data: dict) -> 'scene.Scene':
     """
     Load scene from data schema.

+ 1 - 1
scripts/basics.py

@@ -6,6 +6,6 @@ def test_example01():
     prepare('02.yaml')
     sq = StairsGroup(brick, 5)
     add_group(sq)
-
+    set_marks(50)
     while is_running():
         update()