Commits

Dominic Kexel committed caa654d Draft

use generator to hit building

Comments (0)

Files changed (1)

         explode = True
     if self._current[1] >= SCREEN_HEIGHT:
         explode = True
-        
-    for a in self.scene._actors:
-      if isinstance(a, Building):
-        mask = pygame.mask.from_surface(a._surf)
-        fixed = sub(c, a.pos)
-        try: 
-          if mask.get_at(fixed): 
-            explode = True
-            a.hit()
-        except IndexError: pass
+    
+    buildings = ((b, b.get_mask()) for b in self.scene._actors if isinstance(b, Building))
+    
+    for b, m in buildings:
+      try: 
+        if m.get_at(sub(c, b.pos)): 
+          explode = True
+          b.hit()
+      except IndexError: pass
         
     if explode:
       self._moving = False
     self._img = get_art(self.__class__.__name__.lower())
     self._surf = build_surface(self.scene._game.tick, self._img)
   
+  def get_mask(self):
+    return pygame.mask.from_surface(self._surf)
+  
   def hit(self):
     self._is_hit = True
     self._on_hit()