1# To install pygame, type 'pip install pygame' in the
2# windows powershell or the os terminal
3
4# To create a blank screen as a setup for a game, use:
5import pygame
6import sys
7
8pygame.init()
9
10clock = pygame.time.Clock()
11
12FPS = 30 # How many times the screen will update per second
13
14screen_width = 600 # How wide the window will be
15screen_height = 600 # how high the window will be
16
17screen = pygame.display.set_mode((screen_width, screen_height)) # creates the screen
18
19while True:
20 clock.tick(FPS) # updates the screen, the amount of times it does so depends on the FPS
21 for event in pygame.event.get(): # Allows you to add various events
22 if event.type == pygame.QUIT: # Allows the user to exit using the X button
23 pygame.quit()
24 sys.exit()
25
26
27
28
29
30
1import pygame
2pygame.init()
3
4win = pygame.display.set_mode((500,500))
5pygame.display.set_caption("First Game")
6
7x = 50
8y = 50
9width = 40
10height = 60
11vel = 5
12
13run = True
14
15while run:
16 pygame.time.delay(100) # This will delay the game the given amount of milliseconds. In our casee 0.1 seconds will be the delay
17
18 for event in pygame.event.get(): # This will loop through a list of any keyboard or mouse events.
19 if event.type == pygame.QUIT: # Checks if the red button in the corner of the window is clicked
20 run = False # Ends the game loop
21
22pygame.quit() # If we exit the loop this will execute and close our game
23
1# Simple pygame program
2 2
3 3 # Import and initialize the pygame library
4 4 import pygame
5 5 pygame.init()
6 6
7 7 # Set up the drawing window
8 8 screen = pygame.display.set_mode([500, 500])
9 9
1010 # Run until the user asks to quit
1111 running = True
1212 while running:
1313
1414 # Did the user click the window close button?
1515 for event in pygame.event.get():
1616 if event.type == pygame.QUIT:
1717 running = False
1818
1919 # Fill the background with white
2020 screen.fill((255, 255, 255))
2121
2222 # Draw a solid blue circle in the center
2323 pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)
2424
2525 # Flip the display
2626 pygame.display.flip()
2727
2828 # Done! Time to quit.
2929 pygame.quit()