Draws the map to a Surface object, including the player and stars. This function does not call pygame.display.update(), nor does it draw the "Level" and "Steps" text in the corner.
(mapObj, gameStateObj, goals)
| 534 | |
| 535 | |
| 536 | def drawMap(mapObj, gameStateObj, goals): |
| 537 | """Draws the map to a Surface object, including the player and |
| 538 | stars. This function does not call pygame.display.update(), nor |
| 539 | does it draw the "Level" and "Steps" text in the corner.""" |
| 540 | |
| 541 | # mapSurf will be the single Surface object that the tiles are drawn |
| 542 | # on, so that it is easy to position the entire map on the DISPLAYSURF |
| 543 | # Surface object. First, the width and height must be calculated. |
| 544 | mapSurfWidth = len(mapObj) * TILEWIDTH |
| 545 | mapSurfHeight = (len(mapObj[0]) - 1) * TILEFLOORHEIGHT + TILEHEIGHT |
| 546 | mapSurf = pygame.Surface((mapSurfWidth, mapSurfHeight)) |
| 547 | mapSurf.fill(BGCOLOR) # start with a blank color on the surface. |
| 548 | |
| 549 | # Draw the tile sprites onto this surface. |
| 550 | for x in range(len(mapObj)): |
| 551 | for y in range(len(mapObj[x])): |
| 552 | spaceRect = pygame.Rect((x * TILEWIDTH, y * TILEFLOORHEIGHT, TILEWIDTH, TILEHEIGHT)) |
| 553 | if mapObj[x][y] in TILEMAPPING: |
| 554 | baseTile = TILEMAPPING[mapObj[x][y]] |
| 555 | elif mapObj[x][y] in OUTSIDEDECOMAPPING: |
| 556 | baseTile = TILEMAPPING[' '] |
| 557 | |
| 558 | # First draw the base ground/wall tile. |
| 559 | mapSurf.blit(baseTile, spaceRect) |
| 560 | |
| 561 | if mapObj[x][y] in OUTSIDEDECOMAPPING: |
| 562 | # Draw any tree/rock decorations that are on this tile. |
| 563 | mapSurf.blit(OUTSIDEDECOMAPPING[mapObj[x][y]], spaceRect) |
| 564 | elif (x, y) in gameStateObj['stars']: |
| 565 | if (x, y) in goals: |
| 566 | # A goal AND star are on this space, draw goal first. |
| 567 | mapSurf.blit(IMAGESDICT['covered goal'], spaceRect) |
| 568 | # Then draw the star sprite. |
| 569 | mapSurf.blit(IMAGESDICT['star'], spaceRect) |
| 570 | elif (x, y) in goals: |
| 571 | # Draw a goal without a star on it. |
| 572 | mapSurf.blit(IMAGESDICT['uncovered goal'], spaceRect) |
| 573 | |
| 574 | # Last draw the player on the board. |
| 575 | if (x, y) == gameStateObj['player']: |
| 576 | # Note: The value "currentImage" refers |
| 577 | # to a key in "PLAYERIMAGES" which has the |
| 578 | # specific player image we want to show. |
| 579 | mapSurf.blit(PLAYERIMAGES[currentImage], spaceRect) |
| 580 | |
| 581 | return mapSurf |
| 582 | |
| 583 | |
| 584 | def isLevelFinished(levelObj, gameStateObj): |