1python3 -m pip install pygame <<<(mac)>>>
2or
3python -m pip install pygame <<<(windows)>>>
4or
5sudo apt install python3-pygame <<<(ubuntu)>>>
1# on your terminal :
2pip install pygame
3
4# check if pygame run :
5py -m pygame.examples.aliens
6# if a window is open -> pygame is correctly installed
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