forked from rczyrnik/pygame_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygame_tutorial_1.py
63 lines (42 loc) · 1.58 KB
/
pygame_tutorial_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
Change the rectangle's color when we click anywhere
'''
# IMPORTS
import sys
import pygame
''' ADD ME! '''
import random # <-- HERE!
# INITIALIZE PYGAME
pygame.init()
# CREATE THE SCREEN -------------------------------
# width, height
screen = pygame.display.set_mode((400, 300))
# red, green, blue
screen.fill( (100, 100, 200) )
# ADD A RECTANGLE ---------------------------------
# width, height
my_shape = pygame.Surface((100, 50))
# red, green, blue
my_shape.fill( (0, 0, 255) )
my_shape_rect = my_shape.get_rect()
# x, y
my_shape_rect.topleft = (200,150)
# DISPLAY IT ALL ----------------------------------
screen.blit(my_shape, my_shape_rect)
pygame.display.update()
# RUN THE GAME ------------------------------------
''' CHANGE ME! '''
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN: # <-- ADD ME!
red = random.randint(0, 255) # <-- ADD ME!
blue = random.randint(0, 255) # <-- ADD ME!
green = random.randint(0, 255) # <-- ADD ME!
my_shape.fill((red, green, blue)) # <-- ADD ME!
# Display It All To The Screen # <-- ADD ME!
screen.fill((100,100,200)) # <-- ADD ME!
screen.blit(my_shape, my_shape_rect) # <-- ADD ME!
pygame.display.update() # <-- ADD ME!