User Tools

Site Tools


user:bh011695:pygametutorial:intro
intro.py
#!/usr/bin/env python
 
#intro.py
#
#Just a quick introduction to opening a pygame window
#and general logic flow of a pygame program.
#
#Pygame program flow:
#{
#import libraries
#
#class declarations
#
#variable initialization
#
#main game loop
#
#}
#
#
import pygame
#Variable declarations
screen = pygame.display.set_mode((640, 480)) #Opens a pygame window @ 640 X 480
pygame.display.set_caption("Window Title") #Window title of the pygame window
running = True 	#As long as this is set to true the main loop will execute
clock = pygame.time.Clock()	#Pygame clock
FPS = 60	#Used to set the game's framerate
BG_COLOR = (0, 0, 0)	#RGB value for black
 
#Main game loop
while running:
	screen.fill(BG_COLOR)	#Sets the background color
 
	#For loop that checks for pygame events
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			running = False
 
	pygame.display.flip()	#Updates the display
	clock.tick(FPS)	#Sets the game to run at X FPS
#End main game loop
user/bh011695/pygametutorial/intro.txt · Last modified: 2010/12/13 23:16 by bh011695