杀死敌人后如何添加血粒子效果?



我有一个用生命条左右移动的敌人,但是当敌人死亡时,我怎么能添加粒子,就像敌人被杀死时的血粒子一样,它出现并倒下并投掷长矛?

示例:>>>视频中,我杀死了敌人并删除了它,我怎样才能使加载血液颗粒与刚刚死亡的敌人相同的位置

这是我的敌人职业

class enemys:
def __init__(self,x,y,height,width,end):
self.x = x
self.y =y
self.esright = [pygame.image.load("esright1.png"),
pygame.image.load("esright1.png"),
pygame.image.load("esright2.png"),
pygame.image.load("esright3.png"),
pygame.image.load("esright4.png"),
pygame.image.load("esright5.png"),
pygame.image.load("esright6.png"),
pygame.image.load("esright7.png"),
pygame.image.load("esright8.png"),
pygame.image.load("esright9.png"),
pygame.image.load("esright10.png"),
pygame.image.load("esright11.png"),
pygame.image.load("esright12.png"),
pygame.image.load("esright13.png"),
pygame.image.load("esright14.png"),
pygame.image.load("esright15.png"),
pygame.image.load("esright16.png"),
pygame.image.load("esright17.png"),
]
self.esleft = [pygame.image.load("esleft1.png"),
pygame.image.load("esleft1.png"),
pygame.image.load("esleft2.png"),
pygame.image.load("esleft3.png"),
pygame.image.load("esleft4.png"),
pygame.image.load("esleft5.png"),
pygame.image.load("esleft6.png"),
pygame.image.load("esleft7.png"),
pygame.image.load("esleft8.png"),
pygame.image.load("esleft9.png"),
pygame.image.load("esleft10.png"),
pygame.image.load("esleft11.png"),
pygame.image.load("esleft12.png"),
pygame.image.load("esleft13.png"),
pygame.image.load("esleft14.png"),
pygame.image.load("esleft15.png"),
pygame.image.load("esleft16.png"),
pygame.image.load("esleft17.png"),
]
self.esright = [pygame.transform.scale(image,(image.get_width()//3,image.get_height()//3)) for image in self.esright]
self.esleft = [pygame.transform.scale(image,(image.get_width()//3,image.get_height()//3)) for image in self.esleft]
self.height = height
self.width = width
self.anim_index = 0
self.distance = 80
self.speed = 8
self.vel = 3
self.path = [x,end]
self.Walking_index = 0
self.hitbox = (self.x + 17, self.y + 2, 31, 57)
self.rect = pygame.Rect(x,y,height,width)
COOLDOWN = 30
# enemys health
self.health = 10
self.visible = True
# this makes the enemy move right and left
def draw(self,window):
self.move()
if self.Walking_index + 1 >= 33:
self.Walking_index = 0
if self.vel > 0:
window.blit(self.esright[self.Walking_index//3], (self.x,self.y))
self.Walking_index += 1
else:
window.blit(self.esleft[self.Walking_index//3], (self.x,self.y))
self.Walking_index += 1
# this moves the enemy left and right
def move(self):
if self.visible:
if self.vel > 0:
if self.x + self.vel < self.path[1]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.Walking_index = 0
else:
if self.x - self.vel >  self.path[0]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.Walking_index = 0
# the hit box for the enemy the health
pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 20, 70, 10)) # NEW
pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 20, 70 - (5 * (10 - self.health)), 10))
self.hitbox = (self.x + 47, self.y + 31, 50, 72)

# THIS PART MAKES  the enemy not scroll with the player
def scroll(self,sx, sy):
self.x += sx
self.y += sy
self.path[0] += sx
self.path[1] += sx

当敌人的生命值达到0时,敌人被删除 删除粒子后如何添加粒子? 从敌人位置掉落的血粒


# enemys 1
for bullet in bullets:
if bullet.rect.colliderect(enemys2.hitbox):
if enemys2.health > -5:
enemys2.health -= 1
bullets.pop(bullets.index(bullet))
hitesound.play()
# this function calss the -5 text appearing and dispearing on my screen
minusenemyhealthtext()
else:
for oe in range(len(enemyings)-1,-1,-1):
deathsound.play()
del enemyings[oe]

以下是您的选择:

  1. 获取一个 GIF,将其拆分为多个图像,然后一个接一个地显示每个图像。在课堂上完成所有这些。
  2. 创建一个类(血液类(,该类
  3. 将绘制另一个类(粒子类(的实例,该类只是向外移动并在一段时间后消失。

我不会为你写代码,你必须自己写,但这就是你的方式。

最新更新