WXr/5.py

22 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#处理鼠标和键盘事件的方法
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() #执行飞机类中存储子弹的方法