上传文件至 ''

This commit is contained in:
206530311 2021-06-15 17:30:25 +08:00
parent cabdf1654a
commit fe0b81093c
1 changed files with 22 additions and 0 deletions

22
5.py Normal file
View File

@ -0,0 +1,22 @@
#处理鼠标和键盘事件的方法
def key_control(aircraft_temp):
#获取当前等待处理的事件使用for循环遍历里面的事件
for event in pygame.event.get():
#判断是否点击了退出按钮
if event.type == QUIT:
print("exit") #输出“exit”
exit() #退出窗口
#判断是不是键盘按下事件
elif event.type == KEYDOWN:
#检测按键是a或者left
if event.key == K_a or event.key == K_LEFT:
print('left') #输出“left”
aircraft_temp.move_left() #执行飞机左移方法
#检测按键是d或者right
elif event.key == K_d or event.key == K_RIGHT:
print('right') #输出“right”
aircraft_temp.move_right() #执行飞机右移方法
#检测按键是不是空格键
elif event.key == K_SPACE:
print('space') #输出“space”
aircraft_temp.fire() #执行飞机类中存储子弹的方法