Bläddra i källkod

set_lives() added to character.

Zero! Studio 1 år sedan
förälder
incheckning
a0e3e97410
4 ändrade filer med 21 tillägg och 3 borttagningar
  1. 1 0
      data/02.yaml
  2. 19 0
      jogai/character.py
  3. 1 1
      jogai/settings.py
  4. 0 2
      scripts/basics.py

+ 1 - 0
data/02.yaml

@@ -5,6 +5,7 @@ characters:
   protagonist:
     gravitative: True
     score: 10
+    lives: 5
     speed: 20
     width: 50
     position: [465, 300]

+ 19 - 0
jogai/character.py

@@ -43,6 +43,7 @@ class Character(pygame.sprite.Sprite):
         _('gravitative'),
         _('height'),
         _('keys'),
+        _('lives'),
         _('position'),
         _('score'),
         _('speed'),
@@ -77,6 +78,7 @@ class Character(pygame.sprite.Sprite):
         self.collidable = True
         self.flipped = {'horizontal': False, 'vertical': False}
         self.score = None
+        self.lives = None
 
         super().__init__()
         self.load(image_filename)
@@ -539,6 +541,23 @@ class Character(pygame.sprite.Sprite):
         )
         self.rect = self.image.get_rect()
 
+    def set_lives(self, lives: int):
+        """
+        Set the character lives.
+
+        Parameters:
+            lives: The character lives
+
+        Examples:
+            >>> protagonist = Character('protagonist.png')
+            >>> protagonist.set_lives(5)
+        """
+
+        if self.lives is None:
+            self.lives = texts.LevelBar(lives)
+            _globals.vg_levelbars.append(self.lives)
+        self.lives.set(lives)
+
     def set_keys(self, predefined_keys: dict):
         """
         Set the character predefined keys to perform actions.

+ 1 - 1
jogai/settings.py

@@ -33,7 +33,7 @@ SCOREBOARD_POSITION = (20, 20)
 
 # LEVELBARS
 LEVELBARS_MAX_PARTS = 25
-LEVELBARS_DEFAULT_WIDTH = 250
+LEVELBARS_DEFAULT_WIDTH = 180
 LEVELBARS_DEFAULT_HEIGHT = 20
 LEVELBARS_DEFAULT_THICK = 3
 LEVELBARS_DEFAULT_POSITION = (WINDOW_WIDTH - LEVELBARS_DEFAULT_WIDTH - 20, 25)

+ 0 - 2
scripts/basics.py

@@ -6,8 +6,6 @@ def test_example01():
     prepare('02.yaml')
     sq = StairsGroup(brick, 5)
     add_group(sq)
-    lb = LevelBar(15)
-    add_levelbar(lb)
 
     while is_running():
         update()