From 6e9d95d271477dd407302b68d3cc132be1124cb1 Mon Sep 17 00:00:00 2001 From: JoniHintz Date: Thu, 27 Dec 2018 00:55:01 +0100 Subject: [PATCH 1/3] Fix #9 bug with ownerless projectiles \n Remove remaining projectiles when their owner is removed form the game. --- src/combatsystem.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/combatsystem.py b/src/combatsystem.py index 9f84863..3ba347d 100644 --- a/src/combatsystem.py +++ b/src/combatsystem.py @@ -109,13 +109,13 @@ def check_projectile_collision(self): stun_ev = events.EntityStunned(collider_ID, attack.stun) self.event_manager.post(stun_ev) else: + #Enemy dies #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) - #Enemy dies ev_die = events.EntityDies(collider_ID) self.event_manager.post(ev_die) if not collider_ID == attacks_ID: @@ -135,6 +135,13 @@ 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: + for attack in self.world.attacks[entity_ID]: + for projectile in attack.particles: + projectile.life = -1 + ev_die = events.EntityDies(projectile.entity_ID) + self.event_manager.post(ev_die) self.world.destroy_entity(entity_ID) if entity_ID == self.world.player: self.reset_the_world = True @@ -204,4 +211,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 \ No newline at end of file +# pass From f4c5178cd8ab57967c2564d4afc82075b58f1b93 Mon Sep 17 00:00:00 2001 From: JoniHintz Date: Thu, 27 Dec 2018 01:04:47 +0100 Subject: [PATCH 2/3] Update combatsystem.py --- src/combatsystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/combatsystem.py b/src/combatsystem.py index 3ba347d..a39bb59 100644 --- a/src/combatsystem.py +++ b/src/combatsystem.py @@ -109,13 +109,13 @@ def check_projectile_collision(self): stun_ev = events.EntityStunned(collider_ID, attack.stun) self.event_manager.post(stun_ev) else: - #Enemy dies #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) + #Enemy dies ev_die = events.EntityDies(collider_ID) self.event_manager.post(ev_die) if not collider_ID == attacks_ID: From 053da0383dd09fda6e67d2b3b67a5ff32e02b026 Mon Sep 17 00:00:00 2001 From: JoniHintz Date: Fri, 28 Dec 2018 11:52:00 +0100 Subject: [PATCH 3/3] refactor extract remove projetiles to function --- src/combatsystem.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/combatsystem.py b/src/combatsystem.py index a39bb59..76aff13 100644 --- a/src/combatsystem.py +++ b/src/combatsystem.py @@ -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) @@ -137,16 +132,22 @@ 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: - for attack in self.world.attacks[entity_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(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.