aero26
aero26

Reputation: 155

Why Can't I getX for this Point?

    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

So I've draw a list of stars and made a list of their centerpoints. Then I've got a function that gets the difference between the center of a given star and then compares it to that of a user controlled circle. The program breaks in the getDistance function, claiming that getX is not possible for a 'list' object.

Upvotes: 0

Views: 2630

Answers (1)

Ismail Badawi
Ismail Badawi

Reputation: 37187

You have a typo in checkForStarCollision. The line

collide = balloonStarCollide(balloon, stars)

should be

collide = balloonStarCollide(ballon, star)

Assuming stars is a list, that would explain your error message.

Upvotes: 2

Related Questions