Check bullets and enemies are on the same level
authorNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 23:43:58 +0000 (01:43 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 5 Mar 2016 23:43:58 +0000 (01:43 +0200)
koperkapel/gamelib/enemy_roach.py
koperkapel/scenes/level.py

index 83523b6d4fdd5caeb0c7dce1dd47ff91bbc00668..b09c3aa0f98af86c03169af0824f05935ddfc259 100644 (file)
@@ -15,6 +15,7 @@ def get_enemy_roach(level):
     roach.health = 5
     roach.angle = 0
     roach.level = level
+    roach.level_layer = 'floor'  # always the case for now
     roach.move = partial(move, roach)
     roach.last_moved = 0
     roach.last_attacked= 0
index 379b8bf705e79ea32127a5681155a0ec28de585e..d4f3b0d12e3f8285f8c7278b185ba09f3aeb3a5f 100644 (file)
@@ -259,7 +259,7 @@ class GameLevelScene(BaseLevelScene):
     def _check_for_bullet_hits(self):
         for bullet in list(self._bullets):
             for enemy in list(self._enemies):
-                if enemy.collidepoint(bullet.pos):
+                if enemy.collidepoint(bullet.pos) and bullet.level_layer == enemy.level_layer:
                     self._hit_enemy(enemy, bullet.weapon)
                     self._bullets.remove(bullet)