Completed exercise 12-1 Blue Sky
This commit is contained in:
parent
58e7087d8d
commit
3a58770176
37
Chapter_12/blue_sky.py
Normal file
37
Chapter_12/blue_sky.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# Exercise 12-1 Blue Sky
|
||||||
|
# Learning Objective: Create a gui with a blue background using pygame module.
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self):
|
||||||
|
"""Initialize game and create resources"""
|
||||||
|
pygame.init()
|
||||||
|
self.clock = pygame.time.Clock()
|
||||||
|
self.screen = pygame.display.set_mode((1024, 768))
|
||||||
|
pygame.display.set_caption("Blue Sky")
|
||||||
|
|
||||||
|
def run_game(self):
|
||||||
|
"""Start main game loop"""
|
||||||
|
while True:
|
||||||
|
#Listen for events
|
||||||
|
self._check_events()
|
||||||
|
self._update_screen()
|
||||||
|
self.clock.tick(60)
|
||||||
|
|
||||||
|
def _check_events(self):
|
||||||
|
"""Respond to keypresses and mouse events"""
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
def _update_screen(self):
|
||||||
|
self.screen.fill((135, 193, 255))
|
||||||
|
# refresh display
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# Create game instance and run game
|
||||||
|
bluesky = Game()
|
||||||
|
bluesky.run_game()
|
||||||
Loading…
x
Reference in New Issue
Block a user