Esempio n. 1
0
def main_loop(games):
  keep_running = True
  show_splash = True
  ticks = 0
  banana = Banana()
  splash = Splash()

  while show_splash:
    delta = timer.tick(fps)
    splash.draw(delta)
    screen.blit(splash.surface, (0, 0))
    splash.new_generation()
    splash.iterate()
    pygame.display.flip()

    for e in pygame.event.get():
      if e.type is pygame.KEYDOWN and e.key == pygame.K_SPACE:
        show_splash = False
      if e.type is pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
        keep_running = False
        show_splash = False

  while keep_running:
    timer.tick(fps)
    screen.fill(black)

    for e in pygame.event.get():
      if e.type is pygame.KEYDOWN and (e.key == pygame.K_ESCAPE or e.key == pygame.K_SPACE):
        keep_running = False

    for i, game in enumerate(games):
      game.playSound(ticks)
      game.change_column_color(ticks)
      game.draw()
      screen.blit(game.surface, ((i%2)*game_screen_width,(i/2)*game_screen_height))

    banana.draw(ticks)
    screen.blit(banana.surface, (game_screen_width, game_screen_height))
    pygame.draw.line(screen, white, (0, game_screen_height), (2*game_screen_width, game_screen_height))
    pygame.draw.line(screen, white, (game_screen_width, 0), (game_screen_width, 2*game_screen_height))
    pygame.display.flip()

    ticks += 1

    if ticks == 16:
      ticks = 0

      for game in games:
        game.new_generation()
        game.iterate()