我正在创建一个游戏,当你杀死一个暴徒时,会出现另外两个。我有它,所以当你杀死一个暴徒时,另外两个会出现,但只有一个保持可见并且表现得像它应该的那样。另一个只是出现然后消失。我怎样才能得到它,以便他们两个都按照他们应该的方式行事。这是我到目前为止所拥有的:
[暴民类]
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.left, self.rect.top = location
self.rect.right, self.rect.bottom = location
self.rect.center = location
self.speed = random
self.hp = 4
def update(self):
if self.hp == 0:
mobs.add(self)
self.image = ENEMY
self.pos = [0,0]
self.hp = 4
def moveH(self):
if self.rect.centerx >= Player.rect.centerx:
self.rect.left = self.rect.left - 4
elif self.rect.centerx <= Player.rect.centerx:
self.rect.left = self.rect.left + 4
def moveV(self):
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 Mob.hp == 0:
score = score + 1
Mob.kill()
new_mobs = MOB([50, 50]), MOB([60, 300])
mobs.add(*new_mobs)
[在主循环中重绘和移动]
for Mob in mobs:
Mob.moveV()
Mob.moveH()
screen.blit(Mob.image, Mob.rect)