Module pacai.ui.spritesheet
The graphics for pacman are held in a spritesheet. This file knows how to read a spritesheet and map sprites to tokens.
Functions
def loadSpriteSheet(path)
-
Expand source code
def loadSpriteSheet(path): spritesheet = Image.open(path) sprites = {} # Load the food. miscColumnIndex = 0 for foodTypeBase in SPRITE_SHEET_FOOD_TYPES: for foodItem in [token.FOOD_OFFSET, token.CAPSULE_OFFSET]: foodToken = foodTypeBase + foodItem sprites[foodToken] = _cropSprite(spritesheet, MISC_ROW, miscColumnIndex) miscColumnIndex += 1 # The scared ghost is after the food. sprites[token.SCARED_GHOST_TOKEN] = _cropSprite(spritesheet, MISC_ROW, miscColumnIndex) # Load all the wall sprites. for (wallTypeBase, row) in SPRITE_SHEET_WALL_TYPES: for wallIndex in range(len(SPRITE_SHEET_WALL_ORDER)): adjacentWalls = SPRITE_SHEET_WALL_ORDER[wallIndex] wallToken = token.getWallToken(wallTypeBase, *adjacentWalls) sprites[wallToken] = _cropSprite(spritesheet, row, wallIndex) # Load all the agents. for (agentBaseToken, row) in SPRITE_SHEET_AGENTS: # Load the stopped sprite. sprites[agentBaseToken] = _cropSprite(spritesheet, row, 0) # Now load animations. for direction in Directions.CARDINAL: for frame in range(token.ANIMATION_CYCLE): # We need the offset to crop the sprite, so pass 0 in as the base token. animationOffset = token.getAnimationToken(0, direction, frame) agentToken = agentBaseToken + animationOffset sprites[agentToken] = _cropSprite(spritesheet, row, animationOffset) return sprites