0

我正在尝试创建一个游戏,当你杀死一个敌人时,另外两个将取代它。这个想法是你将无法击败它,因为小怪的数量是无限的。我的问题是产生新的小怪。此外,每当我击中旧的小怪位置时,它会重新出现并继续追逐玩家,并且无法被杀死。这是我到目前为止所拥有的:

[暴徒类]

class MOB(pygame.sprite.Sprite):
    def __init__(self, location):
        self.pos = [0,0]
        self.image = ENEMY
        pygame.sprite.Sprite.__init__(self)
        self.rect = self.image.get_rect()
        self.rect.center = location
        self.speed = random
        self.hp = 4
    def update(self):
        if self.rect.centerx >= Player.rect.centerx:
            self.rect.left = self.rect.left - 4
        if self.rect.centerx <= Player.rect.centerx:
            self.rect.left = self.rect.left + 4
        if self.rect.centery <= Player.rect.centery:
            self.rect.top = self.rect.top + 4
        if self.rect.centery >= Player.rect.centery:
            self.rect.top = self.rect.top - 4

[射击暴徒]

for Mob in mobs:
    if pygame.sprite.collide_rect(Bullet, Mob) == True:
        mobs.remove(Mob)
        Bullet.image = NOBULLET
        Mob.hp = Mob.hp - 2

[杀死暴徒]

for Mob in mobs:
    if Mob.hp == 0:
        mobs.remove(Mob)
            new_mobs = MOB([50,50]), MOB([51, 300]) 
            mobs.add(new_mobs)

[更新画面]

mobs.update()
mobs.draw(screen)
4

0 回答 0