Skip to main content
Engineering LibreTexts

9.19: Adding New Grass and Squirrel Objects

  • Page ID
  •         # add more grass & squirrels if we don't have enough.
            while len(grassObjs) < NUMGRASS:
                grassObjs.append(makeNewGrass(camerax, cameray))
            while len(squirrelObjs) < NUMSQUIRRELS:
                squirrelObjs.append(makeNewSquirrel(camerax, cameray))

    Remember that the NUMGRASS constant was set to 80 and the NUMSQUIRRELS constant was set to 30 at the beginning of the program? These variables are set so that we can be sure there are always plenty of grass and squirrel objects in the active area at all times. If the length of the grassObjs or squirrelObjs drops below NUMGRASS or NUMSQUIRRELS respectively, then new grass and squirrel objects are created. The makeNewGrass() and makeNewSquirrel() functions that create these objects are explained later in this chapter.