Dominic Kexel avatar 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.