赞
踩
1,首先在ship
class Ship():
def __init__(self, ai_settings, screen):
"""初始化飞船并设置其初始位置"""
--snip--
# 空格和发射标志
self.space = False
self.bullets_fire = True
2,首先重构代码,判断空格键按下和放开状态
def check_events(ship):
"""响应按键和鼠标事件"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
check_keydown_events(event, ship)
elif event.type == pygame.KEYUP:
check_keyup_events(event, ship)
def check_keydown_events(event, ship):
"""响应按键"""
if event.key == pygame.K_RIGHT:
ship.moving_right = True
elif event.key == pygame.K_LEFT:
ship.moving_left = True
elif event.key
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。