I am currently creating a shooting game that involves a laser rifle, the idea behind the laser rifle is that its a shot that passes through multiple monsters. which is why I don't remove it from the list yet I want to be able to flag a monster that has been hit so there won't be the issue that while the single shot is passing through the monster sprite it won't cause hit multiple times.
What I am trying to do so far is to distinguish between when its hitting a monster and not and according to that damage or not damage but I am having an issue where because the monster is moving its acting as if they are touching - not touching and touching again causing the damage to repeat itself.
This is what my code looks like:
for bullet in bullet_list:
monster_hit_list = pygame.sprite.spritecollide(bullet,monster_list,False)
if len(monster_hit_list) == 0:
being_hit = False
else:
for monster in monster_hit_list:
if flag == False:
flag = True
if bullet.rel_path != "Sprite Images/Beam.png": # If not lazer
animation_bullet.add(bullet)
if being_hit == False:
monster.current_hp -= My_Man.current_weapon.damage
print monster.current_hp
being_hit = True
if monster.current_hp <= 0:
monster_list.remove(monster)
character_list.remove(monster)
if bullet.rel_path != "Sprite Images/Beam.png": #If not lazer
bullet_list.remove(bullet)
flag = False