-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbulid_window.py
54 lines (39 loc) · 1.02 KB
/
bulid_window.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
# -*- coding:utf-8 -*-
import pygame
from pygame.locals import *
import time
def main():
#1.bulid windows
screen = pygame.display.set_mode((480,852),0,32)
#2.create background picture
background = pygame.image.load("./feiji/background.png")
#3.create a plane
hero = pygame.image.load("./feiji/hero1.png")
x =210
y =700
while True:
screen.blit(background, (0,0))
screen.blit(hero,(x,y))
pygame.display.update()
#获取事件,比如按键等
for event in pygame.event.get():
#判断是否是点击了退出按钮
if event.type == QUIT:
print("exit")
exit()
#判断是否是按下了键
elif event.type == KEYDOWN:
#检测按键是否是a或者left
if event.key == K_a or event.key == K_LEFT:
print('left')
x-=5
#检测按键是否是d或者right
elif event.key == K_d or event.key == K_RIGHT:
print('right')
x+=5
#检测按键是否是空格键
elif event.key == K_SPACE:
print('space')
time.sleep(0.02)
if __name__=="__main__":
main()