so recently someone helped me with removing my health of I collid with my trap Tile But its Removing all instead of just 1 Video --- as you can see in the video it removes all my health instead of just 1 all my healths are stored in a list 1 by 1 its not just 1 image
here is what I did I said if my player collides with my trap tile it should remove 1 of my health and move me back 50
for dude in range(len(dicing)-1,-1,-1):
if playerman.rect.colliderect(dicing[dude].rect):
if dude < len(healths): #Check
del healths[dude]
playerman.x = 50
this is my health class I stored each of the healths in a list V below on my full code
class health:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.heat = pygame.image.load("health.png")
self.heat = pygame.transform.scale(self.heat,(self.heat.get_width()//2,self.heat.get_height()//2))
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
window.blit(self.heat,self.rect)
and this is my trap tile class
class dice:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.ice = pygame.image.load("ice1.png")
self.ice = pygame.transform.scale(self.ice,(self.ice.get_width()-44,self.ice.get_height()-44))
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
player_rect = ice.get_rect(center = self.rect.center)
player_rect.centerx -= -900 # 10 is just an example
player_rect.centery -= 0 # 15 is just an example
window.blit(self.ice,self.rect)
black = (0,0,0)
ice2 = dice(250,390,10,10,black)
dicing = [ice2]
my full code -- its to long to render here full code