I have moved this post from another thread
In python, the following code makes you move reasonably smoothly using
moveXY. It makes you move towards a green flag, but you do not have to move all the way, which is the intended benefit of having
move instead of
moveXY. Note that the code uses
removeFlag, for which you have to buy a flag shaped item.
#this means green flag close distance
gFCDist = 5
sPos = self.pos
sX = sPos.x
sY = sPos.y
greenFlag = self.findFlag("green")
if greenFlag :
gFPos = greenFlag.pos
gFDist = self.distanceTo(greenFlag)
gFDiffX = gFPos.x - sX
gFDiffY = gFPos.y - sY
div = 2
if gFDist > 30:
div = 10
elif gFDist > 15 :
div = 5
elif gFDist <= gFCDist :
gFTX = sX + gFDiffX / div
gFTY = sY + gFDiffY / div
#this is just so that there is no infinite loop. Really we should use self.wait
you can solve the level keeping-time using only this code.
the green flag gets removed if you are close to it, so that it is easier to remove the green flag from the battlefield.
The code will not give your character an instruction if the green flag is too close. This should really be handled differently, but the code would more complex/longer.
The issue on github