请问为什么这个代码在检测碰撞的时候会报错啊,有没有人能帮忙解答一下啊
import pygameimport sys
import random
class jingling(pygame.sprite.Sprite):
def __init__(self,img,weizhi,speed,size):
pygame.sprite.Sprite.__init__(self)
self.witdh,self.hight=size,size
self.image=pygame.image.load(img).convert_alpha()
self.speed=speed
self.zb=self.image.get_rect()
self.zb.left,self.zb.top=weizhi
def mve(self):
self.zb=self.zb.move((self.speed,self.speed))
if self.zb.right<=0:
self.zb.left=self.witdh
elifself.zb.left>=self.witdh:
self.zb.right=0
elif self.zb.bottom<=0:
self.zb.top=self.hight
elif self.zb.top>=self.hight:
self.zb.bottom=0
def zhanxain():
pygame.init()
bg_imag="ywy.png"
img="玩个球.png"
size=witdh,high=800,600
s=pygame.display.set_mode(size)
pygame.display.set_caption('玩个球')
bg=pygame.image.load(bg_imag).convert_alpha()
xh=True
lb1=[]
group=pygame.sprite.Group()
for i in range(5):
weizhi=random.randint(0,witdh-100),random.randint(0,high-100)
speed=
ball=jingling(img,weizhi,speed,size)
lb1.append(ball)
while pygame.sprite.spritecollide(ball,group,False):
ball.zb.left,ball.zb.top =random.randint(0,witdh-100),random.randint(0,high-100)
group.add(ball)
c=pygame.time.Clock()
while xh:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
s.blit(bg, (0, 0))
for e in lb1:
e.mve()
s.blit(e.image,e.zb)
for i in group:
group.remove(i)
if pygame.sprite.spritecollide(i,group,False):
i.speed= -i.speed
i.speed= -i.speed
group.add(i)
pygame.display.flip()
c.tick(30)
if __name__=="__main__":
zhanxain()
仔细读读报错信息! 什么不懂英文? 哦,那要不就别学编程了~
页:
[1]