-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygame_test.py
48 lines (36 loc) · 1.16 KB
/
pygame_test.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
import pygame
from pygame.locals import *
# pygame.init()
screen = pygame.display.set_mode((640, 240))
class Color:
BLACK = (0, 0, 0)
GRAY = (127, 127, 127)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
CYAN = (0, 255, 255)
MAGENTA = (255, 0, 255)
# The easiest way to decode many key
key_dict = {K_k: Color.BLACK, K_r: Color.RED, K_g: Color.GREEN, K_b: Color.BLUE,
K_y: Color.YELLOW, K_c: Color.CYAN, K_m: Color.MAGENTA, K_w: Color.WHITE}
pygame.init()
background = Color.GRAY
caption = "Start"
running = True
while running:
for event in pygame.event.get():
# Quit
if event.type == pygame.QUIT:
running = False
# If the keyboard is pressed
if event.type == KEYDOWN:
if event.key in key_dict:
background = key_dict[event.key]
caption = 'background color = ' + str(background)
pygame.display.set_caption(caption)
screen.fill(background)
pygame.display.update()
pygame.quit()
# 1.9 Explore a simple ball game