我正在尝试创建一个游戏,当你杀死一个敌人时,另外两个将取而代之。由于无数的怪物,你的想法是你无法击败它。我的问题是产生新的怪物。此外,每当我击中旧的小怪位置时,它会重新出现并继续追逐玩家,并且不能被杀死。以下是我到目前为止的情况:
[Mob Class]
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)