-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy path1_build_screen_moving_block.py
48 lines (35 loc) · 1.17 KB
/
1_build_screen_moving_block.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
# Build a screen and a moving block
import pygame
from pygame.locals import *
def draw_block():
surface.fill((110, 110, 5))
surface.blit(block, (block_x, block_y))
pygame.display.flip()
if __name__ == "__main__":
pygame.init()
surface = pygame.display.set_mode((500, 500))
surface.fill((110, 110, 5))
block = pygame.image.load("resources/block.jpg").convert()
block_x, block_y = 100, 100
surface.blit(block, (block_x, block_y))
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.key == K_LEFT:
block_x -= 10
draw_block()
if event.key == K_RIGHT:
block_x += 10
draw_block()
if event.key == K_UP:
block_y -= 10
draw_block()
if event.key == K_DOWN:
block_y += 10
draw_block()
elif event.type == QUIT:
running = False