9.5: Describing the Data Structures

Making Games with Python and Pygame · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    9.5: Describing the Data Structures
    """
    This program has three data structures to represent the player, enemy squirrels, and grass background objects. The data structures are dictionaries with the following keys:
    
    Keys used by all three data structures:
        'x' - the left edge coordinate of the object in the game world (not a pixel coordinate on the screen)
        'y' - the top edge coordinate of the object in the game world (not a pixel coordinate on the screen)
        'rect' - the pygame.Rect object representing where on the screen the object is located.
    Player data structure keys:
        'surface' - the pygame.Surface object that stores the image of the squirrel which will be drawn to the screen.
        'facing' - either set to LEFT or RIGHT, stores which direction the player is facing.
        'size' - the width and height of the player in pixels. (The width & height are always the same.)
        'bounce' - represents at what point in a bounce the player is in. 0 means standing (no bounce), up to BOUNCERATE (the completion of the bounce)
        'health' - an integer showing how many more times the player can be hit by a larger squirrel before dying.
    Enemy Squirrel data structure keys:
        'surface' - the pygame.Surface object that stores the image of the squirrel which will be drawn to the screen.
        'movex' - how many pixels per frame the squirrel moves horizontally. A negative integer is moving to the left, a positive to the right.
        'movey' - how many pixels per frame the squirrel moves vertically. A negative integer is moving up, a positive moving down.
        'width' - the width of the squirrel's image, in pixels
        'height' - the height of the squirrel's image, in pixels
        'bounce' - represents at what point in a bounce the player is in. 0 means standing (no bounce), up to BOUNCERATE (the completion of the bounce)
        'bouncerate' - how quickly the squirrel bounces. A lower number means a quicker bounce.
        'bounceheight' - how high (in pixels) the squirrel bounces
    Grass data structure keys:
        'grassImage' - an integer that refers to the index of the pygame.Surface object in GRASSIMAGES used for this grass object
    """
    

    The comments from lines 1 [37] to 25 [61] are in one large, multi-line string. They describe the keys in the player squirrel, enemy squirrel, and grass objects. In Python, a multi-line string value by itself works as a multi-line comment.


    This page titled 9.5: Describing the Data Structures was last modified on Fri, 08 Nov 2019 21:17:45 GMT and is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Al Sweigart via source content that was edited to the style and standards of the LibreTexts platform.