diff --git a/5.py b/5.py new file mode 100644 index 0000000..7004f3d --- /dev/null +++ b/5.py @@ -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() #执行飞机类中存储子弹的方法 \ No newline at end of file