Python 在pygame中拍摄多个射弹

Python 在pygame中拍摄多个射弹,python,list,pygame,projectile,Python,List,Pygame,Projectile,我有一个导弹类,当按下空格键时,它会获取播放器的位置.fire()使用此位置发射导弹。它一次只拍一张,我怎么拍多张?我听说使用列表会有所帮助 class Missile(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) # Get image of the whole spritesheet self.imgMaster = pyga

我有一个
导弹
类,当按下空格键时,它会获取
播放器
的位置
.fire()
使用此位置发射导弹。它一次只拍一张,我怎么拍多张?我听说使用列表会有所帮助

class Missile(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        # Get image of the whole spritesheet
        self.imgMaster = pygame.image.load("Royalty-Free-Game-art-Spaceships-from-Unlucky-Studio.png")
        self.imgMaster.convert()
        misImgSize = (45, 77)
        # Create a surface to draw a section of the spritesheet
        self.image = pygame.Surface(misImgSize)
        self.image.blit(self.imgMaster, (0,0), ( (71, 1956) ,(misImgSize)) )
        self.image.set_colorkey( self.image.get_at((1,1)))
        self.image = pygame.transform.scale( self.image, (15, 35) )
        # Get rect of sprite
        self.rect = self.image.get_rect()
        # Place missile off-screen at first
        self.rect.center = (-100, -100)
        self.dy = 0

    def fire(self, player_pos):
            self.rect.center = player_pos  # Move Bomb to cannon.
            self.dy = BOMB_SpeedY              # Set its velocity.

    
    def update(self):
        self.rect.centery -= self.dy
    
    def reset(self):
        self.rect.center = (-100, -100)     # This location is off-screen!
        self.dx = 0
事件处理程序中的代码:

clock = pygame.time.Clock()
#  - Set a loop that keeps running until user quits or proceeds
keepGoing = True
while keepGoing:
    # Set FPS of the game - 30 frames per second/tick
    clock.tick(CLOCK_TICK)
    # Every 30 ticks is a second
    tickCount += 1

# Handle any events
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        keepGoing = False 
        print("hi!")
    if event.type == pygame.KEYDOWN:

        if event.key == pygame.K_SPACE:
            missile.fire(player.get_pos())
你必须为导弹建立一个小组。按下空格键时,创建
导弹的新实例
,并将其添加到列表中:

missilesGroup=pygame.sprite.Group()
继续=正确
继续进行时:
# [...]
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
继续=错误
打印(“嗨!”)
如果event.type==pygame.KEYDOWN:
如果event.key==pygame.K_空间:
导弹
导弹发射(玩家获得位置())
导弹组。添加(导弹)
我建议将新的导弹也添加到所有精灵组中

不要“重置”导弹,但要使用以下命令将其移除:

类导弹(pygame.sprite.sprite):
# [...]
def重置(自):
self.kill()

从所有组中移除精灵

你必须为导弹建立一个小组。按下空格键时,创建
导弹的新实例
,并将其添加到列表中:

missilesGroup=pygame.sprite.Group()
继续=正确
继续进行时:
# [...]
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
继续=错误
打印(“嗨!”)
如果event.type==pygame.KEYDOWN:
如果event.key==pygame.K_空间:
导弹
导弹发射(玩家获得位置())
导弹组。添加(导弹)
我建议将新的导弹也添加到所有精灵组中

不要“重置”导弹,但要使用以下命令将其移除:

类导弹(pygame.sprite.sprite):
# [...]
def重置(自):
self.kill()

从所有组中移除精灵