1python3 -m pip install pygame <<<(mac)>>>
2or
3python -m pip install pygame <<<(windows)>>>
4or
5sudo apt install python3-pygame <<<(ubuntu)>>>
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
1try:
2pip install pygame
3else:
4pip3 install pygame
5else:
6python -m pip install pygame
7else:
8python3 -m pip install pygame
9else:
10py -m pip install pygame(this is my method)
11(this is only for windows)
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