acclivity

pySwastik

Jul 22nd, 2021 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import pygame
  2.  
  3. # skeleton demonstration script for maintaining and displaying a count of active lives
  4.  
  5. pygame.init()
  6. clock = pygame.time.Clock()
  7. FPS = 60
  8.  
  9. surface = pygame.display.set_mode((500, 500))
  10.  
  11. ctr_lives = 3           # start with 3 lives
  12. nextime = 10            # First addition of a life will be after 10 seconds
  13. while True:
  14.     for event in pygame.event.get():
  15.         if event.type == pygame.QUIT:
  16.             pygame.quit()
  17.         if event.type == pygame.KEYDOWN:        # Down Arrow pressed?
  18.             if ctr_lives:                       # If we have any lives ...
  19.                 ctr_lives -= 1                  # ... Lose 1 life
  20.     surface.fill((110, 0, 220))
  21.     xpos = 10                                   # x position for life-blob #1
  22.     for _ in range(ctr_lives):                  # Draw a blob for each life we currently have
  23.         heart = pygame.Rect(xpos, 30, 20, 20)
  24.         pygame.draw.rect(surface, 'red', heart)
  25.         xpos += 29                              # compute x position for next life-blob
  26.     time = int(pygame.time.get_ticks() / 1000)
  27.     if time == nextime:         # Is it time to add a life?
  28.         ctr_lives += 1          # - yes
  29.         nextime += 10           # - compute time for next life addition
  30.  
  31.     clock.tick(FPS)
  32.     pygame.display.update()
  33.  
Add Comment
Please, Sign In to add comment