Commits

pygame  committed a933f97

fix sprite.Group.has()

  • Participants
  • Parent commits 2137ff8

Comments (0)

Files changed (6)

 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+January 7, 2001
+	fixed sprite.Group.has
+
 January 6, 2001
 	Merge with bob's inital MacOSX changes
 

File examples/aliens.py

 #! /usr/bin/env python
 
-import random, os.path, sys
+import random, os.path
 
 #import basic pygame modules
 import pygame
     defaultlife = 12
     animcycle = 3
     images = []
-    def __init__(self, actor, longer):
+    def __init__(self, actor):
         pygame.sprite.Sprite.__init__(self, self.containers)
         self.image = self.images[0]
         self.rect = self.image.get_rect()
-        self.life = self.defaultlife * (longer+1)
+        self.life = self.defaultlife
         self.rect.center = actor.rect.center
         
     def update(self):
     def update(self):
         self.rect.move_ip(0, self.speed)
         if self.rect.bottom >= 470:
-            Explosion(self, 0)
+            Explosion(self)
             self.kill()
 
 
         #get input
         for event in pygame.event.get():
             if event.type == QUIT or \
-			(event.type == KEYDOWN and event.key == K_ESCAPE):
-			    return
+                (event.type == KEYDOWN and event.key == K_ESCAPE):
+                    return
         keystate = pygame.key.get_pressed()
 
         # clear/erase the last drawn sprites
         all.clear(screen, background)
-
+        
         #update all the sprites
         all.update()
-        
+
         #handle player input
         direction = keystate[K_RIGHT] - keystate[K_LEFT]
         player.move(direction)
             Bomb(lastalien.sprite)
 
         # Detect collisions
-        for a in pygame.sprite.spritecollide(player, aliens, 1):
+        for alien in pygame.sprite.spritecollide(player, aliens, 1):
             boom_sound.play()
-            Explosion(a, 0)
-            Explosion(player, 1)
-            kills += 1
+            Explosion(alien)
+            Explosion(player)
+            kills = kills + 1
             player.kill()
 
         for alien in pygame.sprite.groupcollide(shots, aliens, 1, 1).keys():
             boom_sound.play()
-            Explosion(alien, 0)
-            kills += 1
+            Explosion(alien)
+            kills = kills + 1
                     
         for bomb in pygame.sprite.spritecollide(player, bombs, 1):         
             boom_sound.play()
-            Explosion(player, 0)
+            Explosion(player)
+            Explosion(bomb)
             player.kill()
 
         #draw the scene

File examples/chimp.py

 
 
 #Import Modules
-import os, sys
-import pygame
+import os, pygame
 from pygame.locals import *
 
 if not pygame.font: print 'Warning, fonts disabled'

File examples/stars.py

 event management"""
 
 
-import time, random, math
-
-import pygame
+import random, math, pygame
 from pygame.locals import *
 
 #constants

File examples/zipshow.py

 #(don't blame me, it's a bug in older SDL_image)
 
 
-import zipfile, sys, glob, os
-import pygame, pygame.image
+import zipfile, sys, glob, pygame
 from cStringIO import StringIO
 from pygame.locals import *
 

File lib/sprite.py

         if hasattr(group, '_spritegroup'):
             if has(group):
                 group.remove_internal(self)
-                del self.__g[g]
+                del self.__g[group]
         else:
             for g in group:
                 if has(g):
                     g.remove_internal(self)
-                    del self.__g[g]
+                    del self.__g[group]
 
     def add_internal(self, group):
         self.__g[group] = 0
            Returns true if the given sprite or sprites are
            contained in the group"""
         has = self.spritedict.has_key
-        if hasattr(sprites, '_spritegroup'):
+        if hasattr(sprite, '_spritegroup'):
+            for sprite in sprite.sprites():
+                if not has(sprite):
+                    return 0
+        else:
+            try: len(sprite) #see if its a sequence
+            except (TypeError, AttributeError):
+                return has(sprite)
+            else:
+                for sprite in sprite:
+                    if not has(sprite):
+                        return 0
+        return 1
+
+        if hasattr(sprite, '_spritegroup'):
             return sprite in has(sprite)
         sprites = sprite
         for sprite in sprites:
                 sprite = sprite[-1]
             except (TypeError, AttributeError): pass
         if sprite is not self.sprite:
-			self.add_internal(sprite)
-			sprite.add_internal(self)
+            self.add_internal(sprite)
+            sprite.add_internal(self)
 
     def remove(self, sprite):
         if hasattr(sprite, '_spritegroup'):