Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- # skeleton demonstration script for maintaining and displaying a count of active lives
- pygame.init()
- clock = pygame.time.Clock()
- FPS = 60
- surface = pygame.display.set_mode((500, 500))
- ctr_lives = 3 # start with 3 lives
- nextime = 10 # First addition of a life will be after 10 seconds
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- if event.type == pygame.KEYDOWN: # Down Arrow pressed?
- if ctr_lives: # If we have any lives ...
- ctr_lives -= 1 # ... Lose 1 life
- surface.fill((110, 0, 220))
- xpos = 10 # x position for life-blob #1
- for _ in range(ctr_lives): # Draw a blob for each life we currently have
- heart = pygame.Rect(xpos, 30, 20, 20)
- pygame.draw.rect(surface, 'red', heart)
- xpos += 29 # compute x position for next life-blob
- time = int(pygame.time.get_ticks() / 1000)
- if time == nextime: # Is it time to add a life?
- ctr_lives += 1 # - yes
- nextime += 10 # - compute time for next life addition
- clock.tick(FPS)
- pygame.display.update()
Add Comment
Please, Sign In to add comment