Grid Minefield: Javascript Help

// The ogre formation is marching at the village.
// We have 90 seconds to build a minefield.
// We'll use their strict formation against them.
hero.toggleFlowers(false);
// Use nested loops to build the grid minefield.
// First iterate x coordinates from 12 to 60 with step 8
var enemy = hero.findNearestEnemy();
for (var x = 12; x < 12 + 8 * 6; x += 8) {
    // For each x iterate y cordinates from 12 to 68 with step 8.
    for (var y = 12; y < 12 + 8 * 7; y += 8) {
        // For each point build "fire-trap" there.
        hero.buildXY("fire-trap", x, y);
    }
    // After each column, it's better to move right to avoid own traps.
    hero.moveXY(hero.pos.x + 8, hero.pos.y);
}
// Now wait and watch the coming ogres.
// When they are near (about 20 metres from the hero) blow mines with your hero.
// Just move at the nearest mine when it's the time.
while (true) {
    if (enemy) {
        if (hero.distanceTo(enemy) <= 20) {
            hero.moveXY(52, 11);
        }
    }
}

My hero places the firetraps fine, but does not move to the firetraps when the ogres come! What is wrong?
link:

Thanks

You are defining the enemy outside the while true loop. This method is perfect for levels where all enemies are spawn in the first frame, but this isn’t the current case.
I think the way to trigger the traps is a little bit stupid and even masochistic.
Coding the situation below is easier and you aren’t harming the hero:


See the leader board for more ways to build the traps.

6 Likes

I can prove that @xython is right because I did the level in Javascript. This method works.
Just do this bellow the for-loop

hero.buildXY("fire-trap", 48, 56);
hero.moveXY(61, 51);
1 Like

Thanks for tips they worked and I finished the level!

here’s how i finally solved this level three years ago:

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.