[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] Does my sprite need a __len__ method?



I'm getting an error message that I can't seem to correct:
Platform instance has no attribute '__len__'
Platform is a sprite class I created.

I call this:
for sprite in self.elves.sprites():

  self.AI.update(sprite, self.players.values(), self.barriers.sprites())


the error occurs when I call:
self.AI.update(

error trying to update: Elf: 0 rect: <rect(1026, 680, 32, 43)> vx: 0 vy: 0 x:
10
42.0 y: 701.0 acc: 0 lives: 3
patrolRect: <rect(0, 657, 1200, 75)> logic: None
ai: <ai.ElfAI instance at 0x00D336F8> ai.update: <bound method ElfAI.update of
<
ai.ElfAI instance at 0x00D336F8>>
barriers: [<Platform sprite(in 2 groups)>, <Platform sprite(in 2 groups)>,
<Plat
form sprite(in 2 groups)>, <Platform sprite(in 2 groups)>, <Platform sprite(in
2
 groups)>, <Platform sprite(in 2 groups)>]
<Platform sprite(in 2 groups)> <rect(241, 637, 310, 20)>
<Platform sprite(in 2 groups)> <rect(585, 101, 20, 530)>
<Platform sprite(in 2 groups)> <rect(68, 340, 260, 20)>
<Platform sprite(in 2 groups)> <rect(822, 277, 290, 20)>
<Platform sprite(in 2 groups)> <rect(720, 732, 480, 20)>
<Platform sprite(in 2 groups)> <rect(0, 790, 1200, 20)>
barrier collisions: -1
dir(Platform): ['__doc__', '__init__', '__module__', '__repr__', 'add',
'add_int
ernal', 'alive', 'center', 'clear', 'clearLast', 'draw', 'groups', 'grow',
'kill
', 'move', 'moveTo', 'place', 'remove', 'remove_internal', 'setImage',
'update']


	def update(self, controlledSprite, playerList, barrierList):
		if not controlledSprite.patrol:
			# create the biggest rect possible centered on the current
			# position and make this the patrol rect. the elf will circle
			# about the patrol rect until it has reason to attack or flee
			#print "setting patrol rect for %s" % controlledSprite
			controlledSprite.patrol = Rect(controlledSprite.rect)
			pr = controlledSprite.patrol
			#print "pr starts as: %s" % pr
			
			# grow left
			while pr.collidelist(barrierList) == -1:
				if pr.left < SCREENRECT.left: break
				pr.move_ip(-1,0)
				pr.inflate_ip(1,0)
			pr.move_ip(1,0)
			pr.inflate_ip(-1,0)
			
			# grow right
			while pr.collidelist(barrierList) == -1:
				if pr.right > SCREENRECT.right: break
				pr.inflate_ip(1,0)
			pr.inflate_ip(-1,0)
			
			# grow up
			while pr.collidelist(barrierList) == -1:
				if pr.top < SCREENRECT.top: break
				pr.move_ip(0,-1)
				pr.inflate_ip(0,1)
			pr.move_ip(0,1)
			pr.inflate_ip(0,-1)
			
			# grow down
			while pr.collidelist(barrierList) == -1:
				if pr.bottom > SCREENRECT.bottom: break
				pr.inflate_ip(0,1)
			pr.inflate_ip(0,-1)
			#print 'patrol rect:', pr
			#print "check controlledSprite still at: %s" % \
			#	controlledSprite.rect
		"""
		if not controlledSprite.logic:
			controlledSprite.logic = 'patrol'
		func = self.logics[controlledSprite.logic]
		func(controlledSprite)"""
		pass

__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com