1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<script>
var zz=new Array()
onload=function(){
i=4
while(i--){
zz[i]=new o(document.images[i],i)
}
setInterval('nextDirection();for(k=0;k<zz.length;k++){zz[k].mouv()}',5)
}
function o(imageRef,index){
this.index=index
this.M=285
this.m=0
this.X=Math.random()*2+1 ;
this.Y=Math.random()*2+1 ;
this.imageRef=imageRef
this.l=parseInt(imageRef.style.left) ;
this.t=parseInt(imageRef.style.top) ;
this.q=this.Q=1
this.mouv=function(){
with(this){
l+=X*q
imageRef.style.left=l+"px"
t+=Y*Q
imageRef.style.top=t+"px"
}
}
}
function nextDirection(){
for(k=0;k<zz.length;k++){
with(zz[k]){
//colission
for(indice=k+1;indice<zz.length;indice++){
if ( ( (zz[indice].t-t)*(zz[indice].t-t)+(zz[indice].l-l)*(zz[indice].l-l)) < 16*16 )
{
if(zz[indice].Q*Q==-1){Q*=-1; zz[indice].Q*=-1}
if(zz[indice].q*q==-1){q*=-1;zz[indice].q*=-1}
if( (zz[indice].Q*Q==1) && (zz[indice].q*q==1))
{
tmpX=X
tmpY=Y
X=zz[indice].X;
Y=zz[indice].Y;
zz[indice].X=tmpX;
zz[indice].Y=tmpY;
}
}
}
//le mur
if(l<m){ q=1}
if(l>M){ q=-1 }
if( t<m){ Q=1 }
if(t>M ){ Q=-1 }
}
}
}
</script> |