1. pygame
  2. Untitled project
  3. pygame

Commits

pygame  committed 2b91eeb

sysfont help

  • Participants
  • Parent commits e15b66d
  • Branches default

Comments (0)

Files changed (3)

File WHATSNEW

View file
 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+December 25, 2003
+    sprite groups are now iterators
+    SysFont better unix parsing
+
 November 18, 2003
     Remove legacy python code. Ver 2.2 is minimum
 

File lib/sprite.py

View file
            Returns an object that can be looped over with
            a 'for' loop. (For now it is always a list, but
            newer version of python could return different
-           objects, like iterators.)"""
+           objects, like iterators.)
+
+           Group is now a python iterator itself, easier to
+           loop over sprites like that."""
         return self.spritedict.keys()
 
+    def __iter__(self):
+        return iter(self.spritedict.iterkeys())
+
     def add(self, sprite):
         """add(sprite)
            add sprite to group
             return [self.sprite]
         return []
 
+    def __iter__(self):
+        if self.sprite:
+            return iter((self.sprite,))
+        else:
+            return iter(())
+
     def add(self, sprite):
         if hasattr(sprite, '_spritegroup'):
             for sprite in sprite.sprites(): pass
     crashed = []
     spritecollide = sprite.rect.colliderect
     if dokill:
-        for s in group.sprites():
+        for s in group:
             if spritecollide(s.rect):
                 s.kill()
                 crashed.append(s)
     else:
-        for s in group.sprites():
+        for s in group:
             if spritecollide(s.rect):
                 crashed.append(s)
     return crashed
     crashed = {}
     SC = spritecollide
     if dokilla:
-        for s in groupa.sprites():
+        for s in groupa:
             c = SC(s, groupb, dokillb)
             if c:
                 crashed[s] = c
                 s.kill()
     else:
-        for s in groupa.sprites():
+        for s in groupa:
             c = SC(s, groupb, dokillb)
             if c:
                 crashed[s] = c
        all sprites must have a "rect" value, which is a
        rectangle of the sprite area."""
     spritecollide = sprite.rect.colliderect
-    for s in group.sprites():
+    for s in group:
         if spritecollide(s.rect):
             return s
     return None

File lib/sysfont.py

View file
     file = open(os.path.join(dir, file))
     numfonts = int(file.readline())
     for line in file.readlines():
-        font, descr = line.split(' ', 1)
+        font, descr = [[line.split(' ', 1)] + ['']][:2]
         if font[-4:].lower() != ".ttf":
             continue
         font = os.path.join(dir, font)