当前位置:   article > 正文

python持续发射子弹_Python外星人入侵项目-重构代码,使得空格键按下后可以连续发射子弹...

编程怎么弄连续射击

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 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/123236
推荐阅读
相关标签
  

闽ICP备14008679号