map.defineObject('attackDrone', {
'type': 'dynamic',
'symbol': 'd',
'color': 'red',
'onCollision': function (player) {
player.killedBy('an attack drone');
},
'behavior': function (me) {
if (me.canMove('up')) {
me.move('up');
}else {
me.move('left');
}
}
});
...
map.defineObject('defenseDrone', {
'type': 'dynamic',
'symbol': 'd',
'color': 'green',
'onCollision': function (player) {
player.killedBy('a defense drone');
},
'behavior': function (me) {
if (me.canMove('up')) {
me.move('up');
}else {
me.move('right');
}
}
});
if( me.getY() < 13 )
me.move( 'down' );
else if( me.getX() > 0 )
me.move('left');
and
if( me.getY() < 13 )
me.move('down');
else if( me.getX() < map.getWidth() )
me.move('right');
attackDrone
if( me.canMove('down') ) {
me.move('down');
} else if (me.canMove('right')) {
me.move('right');
} else {
me.move('left');
}
reinforcementDrone
me.move('left');
defenseDrone
if( me.canMove('down') ) {
me.move('down');
} else if (me.canMove('left')) {
me.move('left');
} else {
me.move('right');
}
all three drone types random moves toward ceil or right:
(Math.random()>.5) ? me.move('right') : me.move('up');
Just reset the collision function:
this.onCollision = function(){};