ville de dragons - Action 2.0/xdhtml-VDD.js
4a503405
 function xDHTML(NomBloc){
 	if( document.layers ){
 		this.xMontrer = 'show';
 		this.xCacher = 'hide';
 		this.xUnite = '';
 	}else{
 		this.xMontrer = 'visible';
 		this.xCacher = 'hidden';
 		this.xUnite = 'px';
 	}
 	if( document.getElementById ){
 		this.xBloc = document.getElementById( NomBloc );
 		this.xStyle = this.xBloc.style;
 	}else if( document.all ){
 		this.xBloc = document.all( NomBloc );
 		this.xStyle = this.xBloc.style;
 	}else{
 		this.xBloc = this.xStyle = null;
 	}
 	
 	return this;
 }
 //changer image
 xDHTML.prototype.changeImage = function(cheminImage){
   var blocImg = this.xBloc.firstChild;
   //var cheminImageBloc = blocImg.getAttribute("src");
   var cheminImageBloc = cheminImage;
   blocImg.setAttribute("src", cheminImageBloc);	
 }
 
 //getter position
 xDHTML.prototype.getTop = function(){
   return parseInt(this.xStyle.top);
 }
 xDHTML.prototype.getLeft = function(){
   return parseInt(this.xStyle.left);
 }
 xDHTML.prototype.getDown = function(){
   var Bas = parseInt(this.xStyle.top);
   Bas = Bas + parseInt(this.xStyle.height);
   return (Bas);
 }
 xDHTML.prototype.getRight = function(){
   var Droite = parseInt(this.xStyle.left);
   Droite = Droite + parseInt(this.xStyle.width);
   return (Droite);
 }
 
 //hitTest
 xDHTML.prototype.HitTest = function ( blocCible ){
 //recuperation du bloc cible
 xBlocCible = new xDHTML( blocCible );
   //debut du hitTest
   if(this.getTop()>=xBlocCible.getDown()){
     if(this.getRight() >= xBlocCible.getLeft() && this.getRight() <= xBlocCible.getRight()){
       if(this.getTop()==xBlocCible.getDown()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getLeft() >= xBlocCible.getLeft() && this.getLeft() <= xBlocCible.getRight()){
       if(this.getTop()==xBlocCible.getDown()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getLeft() <= xBlocCible.getLeft() && this.getRight() >= xBlocCible.getRight()){
       if(this.getTop()==xBlocCible.getDown()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }
   }
 
   if(this.getDown()<=xBlocCible.getTop()){
     if(this.getRight() >= xBlocCible.getLeft() && this.getRight() <= xBlocCible.getRight()){
       if(this.getDown()==xBlocCible.getTop()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getLeft() >= xBlocCible.getLeft() && this.getLeft() <= xBlocCible.getRight()){
       if(this.getDown()==xBlocCible.getTop()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getLeft() <= xBlocCible.getLeft() && this.getRight() >= xBlocCible.getRight()){
       if(this.getDown()==xBlocCible.getTop()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }
   }
 
   if(this.getLeft()>=xBlocCible.getRight()){
     if(this.getTop() <= xBlocCible.getDown() && this.getTop() >= xBlocCible.getTop()){
       if(this.getLeft()==xBlocCible.getRight()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getDown() <= xBlocCible.getDown() && this.getDown() >= xBlocCible.getTop()){
      if(this.getLeft()==xBlocCible.getRight()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getDown() >= xBlocCible.getDown() && this.getTop() <= xBlocCible.getTop()){
       if(this.getLeft()==xBlocCible.getRight()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }
   }
   
   if(this.getRight()<=xBlocCible.getLeft()){
     if(this.getTop() <= xBlocCible.getDown() && this.getTop() >= xBlocCible.getTop()){
       if(this.getRight()==xBlocCible.getLeft()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getDown() <= xBlocCible.getDown() && this.getDown() >= xBlocCible.getTop()){
       if(this.getRight()==xBlocCible.getLeft()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }else if(this.getDown() >= xBlocCible.getDown() && this.getTop() <= xBlocCible.getTop()){
       if(this.getRight()==xBlocCible.getLeft()){
         return( 'true' );
       }else{
         return( 'false' );
       }
     }
   }
   return( 'false' );
 }
 
 
 xDHTML.prototype.MoveTo = function( nX, nY ){
 	if( this.xStyle ){
 		this.xStyle.left = parseInt(nX) + this.xUnite;
 		this.xStyle.top = parseInt(nY) + this.xUnite;
 	}
 }
 
 xDHTML.prototype.MoveToElastic = function( nX, nY ){
 	//initialisation
 	if( this.xStyle ){
 		this.posX = parseInt(this.xStyle.left);
 		this.posY = parseInt(this.xStyle.top);
 	}
 	this.vit_x = 0;
 	this.vit_y = 0;
 	this.arriveX = 500;
 	this.arriveY = 100;
 	this.frottements = 0.8;
 	this.cste_elastic = 0.3;
 	this.itx = 0;
 	this.maxItx = 200;
 	//lancement de l'animation
 	this.tempoMoveTo = null;
 	this.AnimationMoveToElastic();
 }
 
 xDHTML.prototype.AnimationMoveToElastic = function(){
 	if( this.xStyle ){
 		this.posX = parseInt(this.xStyle.left);
 		this.posY = parseInt(this.xStyle.top);
 	}
 	//calcul de déplacement pour la prochaime position
 	this.vit_x = this.vit_x * this.frottements + ( this.arriveX - this.posX )*this.cste_elastic ;
 	this.vit_y = this.vit_y * this.frottements + ( this.arriveY - this.posY )*this.cste_elastic ;
 	//lancement du deplacement
 	this.MoveBy(this.vit_x,this.vit_y);
 	//debut et arret de la boucle recursive
 	if( this.posX >= (this.arriveX-1) && this.posX <= (this.arriveX+1) && this.posY >= (this.arriveY-1) && this.posY <= (this.arriveY+1) ){
 		clearTimeout(this.tempoMoveTo);
 		this.tempoMoveTo = null;
 	}else{
 		/********************************problèmes de cohérence dans le parseur Javascript
 		//this.tempoMoveTo = setTimeout("this.AnimationMoveToElastic()",10);
 											*********/
 		var self = this;
 		this.tempoMoveTo = setTimeout(function(){self.AnimationMoveToElastic();}, 10)
 		
 	}
 }
 
 xDHTML.prototype.MoveBy = function ( nX, nY ){
 	if( this.xStyle ){
 		this.posX = parseInt(this.xStyle.left);
 		this.posY = parseInt(this.xStyle.top);
 		this.xStyle.left = this.posX + parseInt(nX) + this.xUnite;
 		this.xStyle.top = this.posY + parseInt(nY) + this.xUnite;
 	}
 }