Nav apraksta

alien_invasion.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pygame
  2. from pygame.sprite import Group
  3. from settings import Settings
  4. from game_stats import GameStats
  5. from scoreboard import Scoreboard
  6. from button import Button
  7. from ship import Ship
  8. import game_functions as gf
  9. def run_game():
  10. # Initialize pygame, settings, and screen object.
  11. pygame.init()
  12. ai_settings = Settings()
  13. screen = pygame.display.set_mode(
  14. (ai_settings.screen_width, ai_settings.screen_height))
  15. pygame.display.set_caption("Alien Invasion")
  16. # Make the Play button.
  17. play_button = Button(ai_settings, screen, "Play")
  18. # Create an instance to store game statistics, and a scoreboard.
  19. stats = GameStats(ai_settings)
  20. sb = Scoreboard(ai_settings, screen, stats)
  21. # Set the background color.
  22. bg_color = (230, 230, 230)
  23. # Make a ship, a group of bullets, and a group of aliens.
  24. ship = Ship(ai_settings, screen)
  25. bullets = Group()
  26. aliens = Group()
  27. # Create the fleet of aliens.
  28. gf.create_fleet(ai_settings, screen, ship, aliens)
  29. # Start the main loop for the game.
  30. while True:
  31. gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
  32. aliens, bullets)
  33. if stats.game_active:
  34. ship.update()
  35. gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
  36. bullets)
  37. gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
  38. bullets)
  39. gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
  40. bullets, play_button)
  41. run_game()