pygame example
Example 1: how to create a pygame window
import pygame
pygame.init()
back = (192,192,192)
gameDisplay = pygame.display.set_mode((800,600))
pygame.display.set_caption('A bit Racey')
gameDisplay.fill(back)
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
Example 2: install pygame
python3 -m pip install pygame <<<(mac)>>>
or
python -m pip install pygame <<<(windows)>>>
or
sudo apt install python3-pygame <<<(ubuntu)>>>
Example 3: pygame example
1
2
3
4 import pygame
5 pygame.init()
6
7
8 screen = pygame.display.set_mode([500, 500])
9
10
11 running = True
12 while running:
13
14
15 for event in pygame.event.get():
16 if event.type == pygame.QUIT:
17 running = False
18
19
20 screen.fill((255, 255, 255))
21
22
23 pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
24
25
26 pygame.display.flip()
27
28
29 pygame.quit()
Example 4: pygame examples
-m pygame.examples.astriodsmasher
Example 5: pygame alien example
py -m pygame.examples.aliens
Example 6: pygame tutorial
clock = pygame.time.Clock()