-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalien_invasion.py
26 lines (26 loc) · 956 Bytes
/
alien_invasion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys
import pygame
class AlienInvasion:
"""overall class to manage game assets and behaviour"""
def _init_(self):
"""initialise the game, and create game resources"""
pygame.init()
self.screen = pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Alien Invasion")
#set the background colour.
self.bg_color = (230, 230, 230)
def run_game(self):
"""start the main loop for the game."""
while True:
#watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type ==pygame.QUIT:
sys.exit()
#redraw the screen during each pass through the loop.
self.screen.fill(self.bg_color)
#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