Commits

sirchristian  committed 2b2f398

Added a life counter

  • Participants
  • Parent commits 66bb817

Comments (0)

Files changed (2)

                 centery = initialy)
         surface.blit(line, textpos)
 
+def renderLives(numLives, gameSurface):
+    # Print Lives:
+    font = pygame.font.SysFont(FONT, 14)
+    text = 'Lives:'
+    line = font.render(text, True, (20, 20, 220))
+    textpos = line.get_rect(left=0, top=0)
+    gameSurface.blit(line, textpos)
+    
+    # Render little ships
+    for i in range(numLives):
+        tinyShip = pygame.image.load('ship_small.png')
+        tinyShipRect = tinyShip.get_rect(left=textpos.right + 1 + (i * 28))
+        gameSurface.blit(tinyShip, tinyShipRect)
+
+
 def displayEndGame(lost, gameSurface):
     bigfont = pygame.font.SysFont(FONT, 128)
     smallfont = pygame.font.SysFont(FONT, 18)
     #Create The Backgound
     background = pygame.Surface(gameSurface.get_size())
     background = background.convert()
-    background.fill((250, 250, 250))
+    background.fill((255, 255, 255))
 
     #Display The Background
     gameSurface.blit(background, (0, 0))
         # update UI
         gameSurface.blit(background, (0, 0))
         ship.update()
+        renderLives(numLivesLeft, gameSurface)
+
         for baddie in baddies[:]:
             if baddie.update() == False:
                 # baddie is off the screen
         elif numLivesLeft == 0:
             gameOver = True
             displayEndGame(True, gameSurface)
+            topLeft = pygame.Surface((200, 30))
+            topLeft.fill((255, 255, 255))
+            gameSurface.blit(topLeft, (0,0))
 
         pygame.display.flip()
 

File ship_small.png

Added
New image