Ho modificato il tuo codice in due punti evidenziati da dei commenti:
codice:
//------------------------parte aggiuntiva
var incrx=225;
var incry=-150;
_root.onMouseDown=function():Void{
incrx=50;
incry=50;
}
//----------------------fine parte aggiuntiva
_root.total = 75;
MovieClip.prototype.change_objectif = function() {
this.x = 300-Math.random()*600;
this.y = 300-Math.random()*400;
};
MovieClip.prototype.fourmis = function() {
var _l1 = this;
_l1.speed = _l1.speed_init=4;
_l1.change_objectif();
_l1.onEnterFrame = function() {
var _l1 = this;
if (_l1._alpha<100) {
_l1._alpha = _l1._alpha+15;
}
// end if
if (Math.round(Math.random()*100)<3) {
_l1.change_objectif();
}
// end if
var delta_x = _l1._x-_l1.x;
var _l3 = _l1._y-_l1.y;
var targetRotation = -Math.atan2(delta_x, _l3)/0.017453;
//var delta_x2 = _l1._x-_l1._parent._xmouse;
//var delta_y2 = _l1._y-_l1._parent._ymouse;
// ------------------------------------parte modificata
var delta_x2=_l1._x-incrx;
var delta_y2=_l1._y-incry;
// ------------------------------------parte modificata
var dist = Math.sqrt(delta_x2*delta_x2+delta_y2*delta_y2);
if (dist<100) {
if (_l1.son != true) {
if (Math.random()*100<50) {
if (Math.random()*100<50) {
cri.start(0, 1);
} else {
non.start(0, 1);
}
// end if
}
// end if
_l1.son = true;
}
// end if
_l1.speed = (100-dist)/8+6;
var _l2 = -Math.atan2(delta_x2, delta_y2)/0.017453;
_l1.x = -100*Math.sin(_l2*0.017453);
_l1.y = 100*Math.cos(_l2*0.017453);
_l1._rotation = _l2+180;
} else {
_l1.speed = _l1.speed_init;
_l1.son = false;
}
// end if
if (_l1._rotation<targetRotation) {
_l1._rotation = _l1._rotation+5;
}
// end if
if (_l1._rotation>targetRotation) {
_l1._rotation = _l1._rotation-5;
}
// end if
if (Math.sqrt(delta_x*delta_x+_l3*_l3)>_l1.speed) {
_l1.play();
_l1.carton.carton_int.play();
_l1._y = _l1._y-_l1.speed*Math.cos(_l1._rotation*0.017453);
_l1._x = _l1._x+_l1.speed*Math.sin(_l1._rotation*0.017453);
} else {
_l1.stop();
_l1.carton.carton_int.stop();
}
// end if
};
};
stop();
Nella prima parte del codice ho creato due variabili: incrx e incry.
Ad entrambe gli ho dato il valore che le espressioni _l1._parent._xmouse e _l1._parent._ymouse hanno di default. Le variabili incrx e incry sono quelle che ho utilizzato per dare dei valori al posto del movimento del mouse.
Ho anche aggiunto un evento onMouseDown per fare una prova e spostare le formiche sempre nello stesso punto con un click. Io ho messo 50, ma è solo per fare una prova...
Ciao