[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] spritecollide-problem
Hi,
I'm writing a soccer game with pygame. Currently I'm stuck with an error
caused by pygame.sprite.spritecollide.
The error message is:
File "/usr/lib/python2.5/site-packages/pygame/sprite.py", line 482, in
spritecollide
spritecollide = sprite.rect.colliderect
AttributeError: 'list' object has no attribute 'colliderect'
It's thrown in a collision-detection function in the player class:
for border in pygame.sprite.spritecollide(self, borders, False):
direction = border.reflect()
The constructor of the player class goes like this ...
class Player(pygame.sprite.Sprite):
def __init__(self, side, pos, spritesheet, sprites_up,
sprites_down, sprites_left, sprites_right):
pygame.sprite.Sprite.__init__(self)
spritesheet = sprites.Sprites(spritesheet)
self.images_up = spritesheet.imgsat(sprites_up, -1)
self.images_right = spritesheet.imgsat(sprites_right, -1)
self.images_down = spritesheet.imgsat(sprites_down, -1)
self.images_left = spritesheet.imgsat(sprites_left, -1)
# self.image, self.rect = load_png('player.png')
screen = pygame.display.get_surface()
self.image = self.images_up[1]
img_rect = self.image.get_rect()
self.rect = pygame.Rect(img_rect[0], img_rect[1],
img_rect[2], img_rect[3]) # self.image.get_rect()
self.area = screen.get_rect()
self.side = side
self.normal_speed = 5
self.speed = 0
self.direction = [0,0]
self.state = "still"
self.init_pos = pos
self.anim_state = 0
self.reinit()
....
The player class is inherited by a simple Bot class, which currently
only contains a few lines of code:
class Bot(Player, pygame.sprite.Sprite):
def __init__(self, side, pos, spritesheet, sprites_up,
sprites_down, sprites_left, sprites_right):
Player.__init__(self, side, pos, spritesheet, sprites_up,
sprites_down, sprites_left, sprites_right)
All stuff is initialized in the main function:
...
# Initialise players
global player1
player1 = Player("up", [200,200], 'soccer.bmp',player1_images_up,
player1_images_down, player1_images_left,
player1_images_right)
global Bot1_1
bot1_1 = Bot("up", [200,200], 'soccer.bmp',bot1_images_up,
bot1_images_down, bot1_images_left, bot1_images_right)
global border1
border1 = Border("left", [20,20], 'bande.bmp', [0,0,30,100], [30,0])
# Initialise sprites
global borders
borders = pygame.sprite.RenderPlain(border1)
playersprites = pygame.sprite.RenderPlain(player1, bot1_1)
Sorry for copying that much code, but I really don't have a clue where
this bug lurks ...
Any hints?
Thanks in advance
Sven