Take the 2-minute tour ×
Arqade is a question and answer site for passionate videogamers on all platforms. It's 100% free, no registration required.

In Untrusted, how can I pass the many attack and defense droids?

I've tried going down, but they get stuck; I tried sending them right, but they cover the exit.

enter image description here

share|improve this question
    
Alternative approach: override onCollision so you can just walk right through the enemies. –  user2357112 Apr 10 at 5:14
    
Define collision for all the drones to let you through. :-) Check here. Same comment. Try and solve it yourself else I will release one for everyone to see. –  ヴァイシャリ Apr 11 at 16:55

4 Answers 4

up vote 1 down vote accepted

For the red drones, give the following:

if(me.getY()>11)
    me.move('up');
else if(me.getX()>0)
    me.move('left');

The yellow drones can be given this:

me.moveToward('block');

Give the green drones this code:

if(me.getY()>11)
    me.move('up');
else if(me.getX()<map.getWidth()-1)
    me.move('right');

Just move right and the red and green drones will line up and move towards the top corners.

Line 'em up

share|improve this answer

I solved this by simply giving every single drone a random chance to go either 'up' or 'right'.

var z = Math.floor(Math.random() * 2) + 1
switch(z){
case(1):
  me.move('up');
  break;
case(2):
  me.move('right');
  break;
}

Copy and paste to all three drones.

share|improve this answer

I found a cooler way, take a look: red:

moveToward(me, 'dummy1');

nothing at all in yellow

green:

        moveToward(me, 'dummy2');
    }
});
map.defineObject('dummy1', {
    'type': 'dynamic',
    'symbol': 'R',
    'color': 'white',
    'behavior': function (me) {
            }
});

map.defineObject('dummy2', {
    'type': 'dynamic',
    'symbol': '+',
    'color': 'white',
    'behavior': function (me) {
            }
});

map.placeObject(2, 13, 'dummy1');
map.placeObject(42, 11, 'dummy2');

map.defineObject('dummy3', {
    'type': 'dynamic',
    'symbol': '=',
    'color': 'white',
    'behavior': function (me) {`

I love my answer.

share|improve this answer

Red Drones - keep moving the drones left and move your guy up one to avoid them as they approach.

if (me.getY()>11) {
  me.move('left');
} 

Yellow Drones

Nothing, leave the yellow drones right where they are

Green Drones - keep moving the middle drone (y==12) to the right until it reaches (12,29) at which time you move it up one to get it out of way of the exit block

if (me.getY()==12) {
    if (me.getX()==29) {
         me.move('up');
     } else {
         me.move('right');
     }
} 

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.