-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
48 lines (40 loc) · 1.64 KB
/
test.py
File metadata and controls
48 lines (40 loc) · 1.64 KB
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
import pygame
pygame.init()
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255, 50) # This color contains an extra integer. It's the alpha value.
PURPLE = (255, 0, 255)
screen = pygame.display.set_mode((200, 325))
screen.fill(WHITE) # Make the background white. Remember that the screen is a Surface!
clock = pygame.time.Clock()
size = (50, 50)
red_image = pygame.Surface(size)
green_image = pygame.Surface(size)
blue_image = pygame.Surface(size, pygame.SRCALPHA) # Contains a flag telling pygame that the Surface is per-pixel alpha
purple_image = pygame.Surface(size)
red_image.set_colorkey(BLACK)
green_image.set_alpha(50)
# For the 'blue_image' it's the alpha value of the color that's been drawn to each pixel that determines transparency.
purple_image.set_colorkey(BLACK)
purple_image.set_alpha(50)
pygame.draw.rect(red_image, RED, red_image.get_rect(), 10)
pygame.draw.rect(green_image, GREEN, green_image.get_rect(), 10)
pygame.draw.rect(blue_image, BLUE, blue_image.get_rect(), 10)
pygame.draw.rect(purple_image, PURPLE, purple_image.get_rect(), 10)
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
screen.blit(red_image, (75, 25))
elif event.key == pygame.K_2:
screen.blit(green_image, (75, 100))
elif event.key == pygame.K_3:
screen.blit(blue_image, (75, 175))
elif event.key == pygame.K_4:
screen.blit(purple_image, (75, 250))
pygame.display.update()