Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9 Fix bug with ownerless projectiles #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/combatsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ def check_projectile_collision(self):
stun_ev = events.EntityStunned(collider_ID, attack.stun)
self.event_manager.post(stun_ev)
else:
#Remove all projectiles of enemy
for attack in self.world.attacks[collider_ID]:
for projectile in attack.particles:
projectile.life = -1
ev_die = events.EntityDies(projectile.entity_ID)
self.event_manager.post(ev_die)
self.remove_enemy_projectiles(collider_ID)
#Enemy dies
ev_die = events.EntityDies(collider_ID)
self.event_manager.post(ev_die)
Expand All @@ -135,11 +130,24 @@ def check_projectile_collision(self):

def remove_dead_entities(self):
for entity_ID in self.world.to_remove:
#make sure no ownerless projectile stays on the screen
if entity_ID in self.world.attacks:
self.remove_enemy_projectiles(entity_ID)
self.world.destroy_entity(entity_ID)
if entity_ID == self.world.player:
self.reset_the_world = True
self.world.to_remove = list()

def remove_enemy_projectiles(self, enemy_ID):
for attack in self.world.attacks[enemy_ID]:
for projectile in attack.particles:
projectile.life = -1
ev_die = events.EntityDies(projectile.entity_ID)
self.event_manager.post(ev_die)




def execute_attack(self, entity_ID, attack_Nr, spawn_attack_pos=None, attack_dir=None):
"""Entity executes one of its possible attacks if cooldown is ready.

Expand Down Expand Up @@ -204,4 +212,4 @@ def execute_attack(self, entity_ID, attack_Nr, spawn_attack_pos=None, attack_dir
self.world.appearance[effect_ID].play_animation = True

# def handle_collision(self, collider_ID, collidee_ID):
# pass
# pass