From d8775fb1a92f53ae24d936217e34007fdfbda10c Mon Sep 17 00:00:00 2001 From: Nicholas Dyer Date: Fri, 12 May 2023 13:49:26 -0400 Subject: [PATCH] updated comments, made some attributes private --- pocket_friends/game_files/elements/sprites.py | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/pocket_friends/game_files/elements/sprites.py b/pocket_friends/game_files/elements/sprites.py index 968876a..1469c89 100644 --- a/pocket_friends/game_files/elements/sprites.py +++ b/pocket_friends/game_files/elements/sprites.py @@ -58,10 +58,24 @@ class SpriteSheet: class SelectionEgg(pygame.sprite.Sprite): """ - Class for the eggs on the egg selection screen. + Sprite to render the egg on the egg selection screen. + + Attributes: + egg_color (str): The color of the egg (also its name). + description (str): The description of the egg to be displayed when selected. + contentedness (int): How likely the egg is to stay happy, ranges from 0-5. + metabolism (int): How quickly the egg will get hungry, ranges from 0-5. + rect (pygame.Rect): Pygame rectangle used to position the egg on screen. + """ def __init__(self, egg_color, resources_dir): + """ + Creates a SelectionEgg object given an egg color and a resource location. + Args: + egg_color (str): The color egg that should be rendered. + resources_dir (str): The path of the resources directory. + """ pygame.sprite.Sprite.__init__(self) self.egg_color = egg_color @@ -79,20 +93,21 @@ class SelectionEgg(pygame.sprite.Sprite): # Load the egg from the given color and get the bounding rectangle for the image. sprite_sheet = SpriteSheet(resources_dir + '/images/bloops/{0}/egg.png'.format(self.egg_color), resources_dir + '/images/bloops/{0}/egg.json'.format(self.egg_color)) - self.images = sprite_sheet.images + self._images = sprite_sheet.images # Get the rectangle from the first image in the list - self.rect = self.images[0].get_rect() - self.index = 0 - self.image = self.images[self.index] + self.rect = self._images[0].get_rect() + print(type(self.rect)) + self._index = 0 + self.image = self._images[self._index] def update(self): """ - Updates the sprite object. + Update the sprite to the next animation frame. """ # Animate the sprite - self.index = (self.index + 1) % len(self.images) - self.image = self.images[self.index] + self._index = (self._index + 1) % len(self._images) + self.image = self._images[self._index] class InfoText: