BigSteve/PyGame/Basics/000_Intro.py

52 lines
1.9 KiB
Python

# These are the minimum suggested module imports to get started.
# "os" will be used to set a system environment variable
import os
# This environment variable, if present, will supress the printout
# of the PyGame welcome text each time the program is launched
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
# The pygame module itself
import pygame
# We use the sys module to cleanly exit the program
import sys
# This initializes the back-end bits and pieces of pygame
pygame.init()
# Some global variables used to initialize the window
# The width and height are in pixels
WIN_WIDTH = 600
WIN_HEIGHT = 480
# We create a window object used to draw pygame things
# It is initialized with set_mode((width, height))
window = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
# This sets the text in the window's title bar
pygame.display.set_caption("PyGame Basics")
# this clock variable is just an instance of the
# pygame.time.Clock() class so it's less wordy when we
# need to do clock/fps related tasks
clock = pygame.time.Clock()
# The main loop. This while loop runs until "running" is False
running = True
while running is True:
# pygame.event.get() returns any events that have happened
# since the last call to get(). This lets us catch any
# key presses/releases, mouse clicks, etc.
for event in pygame.event.get():
# pygame.QUIT event happens when you click the "X"
# in the window title.
if event.type == pygame.QUIT:
running = False
# flip() updates the entire window with all changes since
# the last update
pygame.display.flip()
# tick() is typically used to set the frame rate of the
# application (fps) so it doesn't run too fast, and doesn't
# use excessive CPU cycles when not needed
clock.tick(60)
# We get to this poince once "running" is False.
# Clean up pygame with the quit() method, then exit program.
pygame.quit()
sys.exit()