coding utf-8 background_image_fil ename back png import pygame from 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
# -*- coding: utf-8 -*-
background_image_filename = 'back.png'
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
background = pygame.image.load(background_image_filename).convert()
x, y = 0, 0
move_x, move_y = 0, 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == KEYDOWN:
if event.key == K_LEFT:
move_x -= 1
elif event.key == K_RIGHT:
move_x += 1
elif event.key == K_UP:
move_y -= 1
elif event.key == K_DOWN:
move_y += 1
elif event.type == KEYUP:
if event.key == K_LEFT:
move_x += 1
elif event.key == K_RIGHT:
move_x -= 1
elif event.key == K_UP:
move_y += 1
elif event.key == K_DOWN:
move_y -= 1
x += move_x
y += move_y
screen.fill((0, 0, 0))
screen.blit(background, (x, y))
pygame.display.update()