def drawAllStars(window,numOfStars):
starlist=list()
for x in range(numOfStars):
cntrx = random.randrange(1000)
cntry= random.randrange(1000)
cntr = graphics.Point(cntrx, cntry)
drawstars(cntrx, cntry, 5, "black", window)
starlist.append(cntr)
print(starlist)
return starlist
def getDistance(point1,point2):
a= point1.getX()
b= point2.getX()
c= point1.getY()
d= point2.getY()
distance= math.sqrt((b-a)**2 + ((d-c)**2))
return distance
def balloonStarCollide(balloon, star):
point1 = balloon.getCenter()
point2= star
distance= getDistance(point1, point2)
if distance <= 30:
return True
else:
return False
def checkForStarCollision(balloon, stars):
for star in stars:
collide = balloonStarCollide(balloon, stars)
if collide == True:
return True
所以我画了一张星星的名单,列出了它们的中心点。然后我得到了一个函数,它可以得到给定星体的中心差,然后将其与用户控制的圆的中心进行比较。程序中断了getDistance函数,声称getX对于“list”对象是不可能的。在
您在
checkForStarCollision
中有一个打字错误。排队应该是
^{pr2}$假设
stars
是一个列表,这将解释您的错误消息。在相关问题 更多 >
编程相关推荐