Level: Drop the Flag


#1

Hey all,

I feel like the code is correct, but there is a significant lag between dropping a flag and building a trap. Likewise, the hero goes to treasure BEFORE building a trap, even after I drop the flag. Solutions? Thanks.

Code in Java:

loop {
var flag = this.findFlag();
var item = this.findNearest(this.findItems());
if (flag) {
// How do we get fx and fy from the flag’s pos?
var fPos = flag.pos;
var fX = fPos.x;
var fY = fPos.y;
this.moveXY(fX, fY);
this.buildXY(“fire-trap”, fX, fY);
this.pickUpFlag(flag);
}
else if (item)
{
var pos = item.pos;
var itemX = pos.x;
var itemY = pos.y;
this.moveXY(itemX, itemY);
}
}


#2

I think part of the lag is that once you tell your hero to get a coin, she will finish moving there before she will respond to the flag. I have some ideas for how to improve this, but it’ll take me a while to implement them. The one thing you could do now is to only move part of the way toward your item each time, but that’s pretty tricky to pull off with the items you have now.

There’s a separate issue for making the flags more responsive which we want to tackle when we get the synchronous PVP fully ready to go.

You may have an easier time with this level if you remove the moveXY to the flag/trap position. Your hero can build from a few meters away, so she doesn’t have to go all the way there; the buildXY will move her into range.


#3

Ah, thanks Nick!

I didn’t look at the parameters of the Build method (mainly bc on my version of Firefox I can’t see item specifics in the “help” area)

Moved the trapBuild further away by modifying the X value :

loop {
var flag = this.findFlag();
var item = this.findNearest(this.findItems());
if (flag) {

        var pos = flag.pos;
        var fX = pos.x;
        var fY = pos.y;
        this.moveXY(fX, fY);
        this.buildXY("fire-trap", **(fX + 3)**, fY);
        this.pickUpFlag(flag);
            }
else if (item)
{
        pos = item.pos;
        var itemX = pos.x;
        var itemY = pos.y;
        this.moveXY(itemX, itemY);
    }
}

What are you supposed to do in the siege of stonehold?
#4

Almost beaten this level but hitting a snag. Here is my code:

loop {
    var flag = this.findFlag();
    if (flag) {
        // How do we get fx and fy from the flag's pos?
        // (Look below at how to get x and y from items.)
        var flagPos = flag.pos;
        var fx = flagPos.x;
        var fy = flagPos.y;        
        this.buildXY("fire-trap", fx, fy);
        this.pickUpFlag(flag);
    }
    else {
        var item = this.findNearestItem();
        if (item) {
            var itemPos = item.pos;
            var itemX = itemPos.x;
            var itemY = itemPos.y;
            this.moveXY(itemX, itemY);
        }
    }
}

The problem is, after I have collected all the coins, I still have one fire trap to place. But since there are no more coins to collect, my guy stays by the fire trap, since "this.moveXY(itemX, itemY) is telling him to. So the ogre comes along and I get blown up. Any suggestions how I could fix this headache?

Thanks!


#5

If no item is around, move to a safe point.

if (item) {
    // collect it
}
else {
    this.move(20, 20); //I have no idea if (20, 20) is safe though.
}

#6

Or you could build a last fire trap in the middle of the empty coin area, just to get yourself to move away.