9.5: Describing the Data Structures
- Page ID
- 13615
""" 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.