Skip to main content
Engineering LibreTexts

9.12: Keeping Track of the Location of Things in the Game World

  • Page ID
    14630
  •     grassObjs = []    # stores all the grass objects in the game
        squirrelObjs = [] # stores all the non-player squirrel objects
        # stores the player object:
        playerObj = {'surface': pygame.transform.scale(L_SQUIR_IMG, (STARTSIZE, STARTSIZE)),
                     'facing': LEFT,
                     'size': STARTSIZE,
                     'x': HALF_WINWIDTH,
                     'y': HALF_WINHEIGHT,
                     'bounce':0,
                     'health': MAXHEALTH}
    
        moveLeft  = False
        moveRight = False
        moveUp    = False
        moveDown  = False
    

    The grassObjs variable holds a list of all the grass objects in the game. As new grass objects are created, they are added to this list. As grass objects are deleted, they are removed from this list. The same goes for the squirrelObjs variable and the enemy squirrel objects.

    The playerObj variable is not a list, but just the dictionary value itself.

    The move variables on lines 12 [120] to 15 [123] track which of arrow keys (or WASD keys) are being held down, just like in a few of the previous game programs.

    • Was this article helpful?