I followed all the directions, but my hero is not collecting the nearest coin. He’s taking extra time to go to a coin farther away, and then he can’t get all the gold coins before they disappear.
I think it is because the variable
minGoldDist starts out so high, and so the first coin is kind of random.
Here is a copy of my code. I have a similar problem in the next level, Mad Maxer Gets Greedy. Help would be greatly appreciated!!
# Coins here disappear after a few seconds! # Get all the gold coins before they vanish. loop: closestGold = None minGoldDist = 9000 coinIndex = 0 coins = self.findItems() # Find the closest coin that is gold. # Remember that gold coins have a value of 3. while coinIndex < len(coins): coin = coins[coinIndex] distance = self.distanceTo(coin) if distance < minGoldDist: if coin.value == 3: closestGold = coin coinIndex += 1 if closestGold: self.moveXY(closestGold.pos.x, closestGold.pos.y)