From 8675caaca6ae89a42dbeebe3e4aff2c4840186a5 Mon Sep 17 00:00:00 2001 From: Nicholas Dyer Date: Mon, 15 May 2023 01:04:45 -0400 Subject: [PATCH] updated docstrings and comments --- pocket_friends/elements/surface.py | 2 +- pocket_friends/game.py | 8 +++++--- pocket_friends/surfaces/selection_info.py | 21 +++++++++++++++++---- pocket_friends/surfaces/title.py | 15 ++++++++------- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pocket_friends/elements/surface.py b/pocket_friends/elements/surface.py index b9f2465..998b84d 100644 --- a/pocket_friends/elements/surface.py +++ b/pocket_friends/elements/surface.py @@ -44,7 +44,7 @@ class GameSurface(pygame.Surface): def preprocess(self): """ - Advance the surface by one frame and draw the background. + Draw the surface background and advance all the surface's sprites by one frame; Run the input handler. """ self._clock.tick(self.game_fps) diff --git a/pocket_friends/game.py b/pocket_friends/game.py index 6354e3b..c7e5008 100644 --- a/pocket_friends/game.py +++ b/pocket_friends/game.py @@ -1,3 +1,5 @@ +"""Main module for the game. Runs setting up the Pygame window and handles scene switching.""" + import pygame import os import pocket_friends @@ -33,13 +35,13 @@ resources_dir = script_dir + '/resources' os.environ['SDL_FBDEV'] = '/dev/fb1' -def start_game(resolution, dev): +def start_game(resolution: int, dev: bool): """ Starts the game. Args: - resolution (int, optional): Resolution to display the game at. Defaults to 240. - dev (bool): Boolean to enable the developer menu at start or not + resolution: Resolution to display the game at. + dev: Boolean to enable the developer menu at start or not """ pygame.init() diff --git a/pocket_friends/surfaces/selection_info.py b/pocket_friends/surfaces/selection_info.py index 4582ce5..3776238 100644 --- a/pocket_friends/surfaces/selection_info.py +++ b/pocket_friends/surfaces/selection_info.py @@ -7,7 +7,22 @@ from pocket_friends.elements import surface class Surface(surface.GameSurface): - def __init__(self, game_res, resources_dir, game_fps, **kwargs): + """ + Surface object for the selection info screen. Contains the selected egg, egg properties, and description in a + scrollable text box. Child class of surface.GameSurface. + """ + def __init__(self, game_res: tuple, resources_dir: str, game_fps: int, **kwargs: str): + """ + Create a selection info surface object. + + Args: + game_res: The internal resolution of the surface. + resources_dir: The path of the game's main resource directory. + game_fps: How many frames per second the game will run at. + + Keyword Args: + selected_egg: The egg that was selected by the previous screen. + """ super().__init__(game_res, resources_dir, game_fps) self._selected_egg = None @@ -25,7 +40,7 @@ class Surface(surface.GameSurface): def update(self): """ - Advance the surface logic by one frame. + Draw objects on the screen and advance the surface logic by one frame; Handle user input. """ self.preprocess() @@ -35,10 +50,8 @@ class Surface(surface.GameSurface): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: - # Scroll down on the info screen. self._info_text.scroll_down() if event.key == pygame.K_UP: - # Scroll up on the info screen. self._info_text.scroll_up() if event.key == pygame.K_a: self.running = False diff --git a/pocket_friends/surfaces/title.py b/pocket_friends/surfaces/title.py index aaa325c..4d2dba0 100644 --- a/pocket_friends/surfaces/title.py +++ b/pocket_friends/surfaces/title.py @@ -5,22 +5,23 @@ from pocket_friends.elements import surface class Surface(surface.GameSurface): """ - Surface object for the title screen. + Surface object for the title screen. Child class of surface.GameSurface. """ def __init__(self, game_res: tuple, resources_dir: str, game_fps: int): """ - Create a title screen surface object + Create a title screen surface object. Args: - game_res (int): The internal resolution of the game - resources_dir (str): The full path of the game's resource directory - game_fps (int): The + game_res: The internal resolution of the surface. + resources_dir: The path of the game's main resource directory. + game_fps: How many frames per second the game will run at. """ super().__init__(game_res, resources_dir, game_fps) - self._frames = 0 - self._delay = 1 + self._frames = 0 # Counter for the number of frames passed + self._delay = 1 # Delay in seconds that the title should stay on screen + # Image of the title screen self._title = pygame.image.load(resources_dir + '/images/title.png').convert_alpha() def update(self):