Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import pygame
- from settings import Settings
- class AlienInvasion:
- """ Overall class to manage game assets and behavior."""
- def __init__(self):
- """Initialize the game, and create game resources."""
- pygame.init()
- self.settings = Settings()
- self.screen = pygame.display.set_mode(
- (self.settings.screen_width, self.settings.screen_height))
- pygame.display.set_caption("Alien Invasion")
- self.ship = Ship(self)
- # set the background color.
- self.bg_color = (230, 230, 230)
- def run_game(self):
- """Start the main loop for the game."""
- while True:
- self._check_events()
- self._update_screen()
- def _check_events(self):
- """Respond to a keypresses and mouse events."""
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit()
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_RIGHT:
- # Move the ship to the right.
- self.ship_rect.x += 1
- def _update_screen(self):
- """Updates imgaes on the screen, and flip to the new screen."""
- self.screen.fill(self.settings.bg_color)
- self.ship.blitme()
- # make the most recently drawn screen visible.
- pygame.display.flip()
- if __name__ == '__main__':
- #make a game instance, and run the game
- ai = AlienInvasion()
- ai.run_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement