Oui, c´est le meme principe, une boucle qui passe la map en revue, un tile a chaque " passage de boucle" et lui attaches sa propriété onRelease;
exactement ca.
Precisions:
1-La fonction pathfinder ne modifie que la variable " tileoualler".
2-Ce systeme de déplacement n´est pas définitif DU TOUT, il me sert surtout à tester mon pathfinding.
et zou vla le code:
function buildMap() {
//on colle tout sur un clip vide ( mieux pour scroller)
this.attachMovie("empty", " clip", d);
this.clip._x = startX;
this.clip._y = startY;
var mapWidth = map[0].length;
var mapHeight = map.length;
//boucle construcrice
for ( var i = 0; i<mapHeight; ++i) {
for ( var j = 0; j<mapWidth; ++j) {
tilename = " t_"+i+"_"+j;
this.clip.attachMovie("tile", tilename, ++d);
this.clip[tilename]._x = ( tileW/2)*(j-i);
this.clip[tilename]._y = ( tileH/2)*(j+i);
tilegraph = map[i][j][0]+1;
this.clip[tilename].gotoAndStop(tilegraph);
//survol du tile
this.clip[tilename].onRollOver = function() {
tilesurvole[0] =
Math.round((((this._x)/(tileW/2))+((this._y)/(tile
H/2)))/2);
tilesurvole[1] = Math.round(tilesurvole[0]-(this._x)/(tileW/2));
this.attachMovie("tileselectionne", " tileselectionne", 2500);
this.tileselectionne._y -= map[tilesurvole[1]][tilesurvole[0]][2];
};
this.clip[tilename].onRollOut = function() {
this.tileselectionne.removeMovieClip();
};
//clique sur le tile, si praticable
if ( map[i][j][1] == 0) {
this.clip[tilename].onRelease = function() {
tileclique = tilesurvole;
};
}
//place le perso
if ( i == charPos[1] && j == charPos[0]) {
this.clip.attachMovie("Klarik-Wizard", " player3", mapWidth*mapHeight+1);
this.clip.player3._x = ( tileW/2)*(j-i);
this.clip.player3._y = ( tileH/2)*(j+i);
this.clip.player3.gotoAndStop(1);
//se deplace si pas à sa place
this.clip.player3.onEnterFrame = function() {
if ( (tileclique[0] ! == charPos[0]) or ( tileclique[1] ! == charPos[1])) {
pathfinder(charPos, tileclique);
this._x = ( tileW/2)*(tileoualler[0]-tileoualler[1]);
this._y = ( tileH/2)*(tileoualler[0]+tileoualler[1]);
charPos = tileoualler;
}
};
}
}
}
}
buildMap();
stop;